mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
Merge pull request #1354 from wonderflow/fixowner
use ApplicationContext as the owner of all the resources if it controlled by Application
This commit is contained in:
@@ -202,7 +202,8 @@ func (r *components) renderComponent(ctx context.Context, acc v1alpha2.Applicati
|
||||
util.PassLabelAndAnnotation(ac, w)
|
||||
// don't pass the following annotation as those are for appConfig only
|
||||
util.RemoveAnnotations(w, []string{oam.AnnotationAppRollout, oam.AnnotationRollingComponent, oam.AnnotationInplaceUpgrade})
|
||||
ref := metav1.NewControllerRef(ac, v1alpha2.ApplicationConfigurationGroupVersionKind)
|
||||
ref := getOwnerFromAC(ac)
|
||||
|
||||
// Don't override if the resources already has namespace, it was set by user or the application controller which is by design.
|
||||
if len(w.GetNamespace()) == 0 {
|
||||
w.SetNamespace(ac.GetNamespace())
|
||||
@@ -817,6 +818,18 @@ func isControlledByApp(ac *v1alpha2.ApplicationConfiguration) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// getOwnerFromAC will check and get the real owner, if the owner is Application, it will use ApplicationContext as owner
|
||||
// or it will make the AC as the owner
|
||||
func getOwnerFromAC(ac *v1alpha2.ApplicationConfiguration) *metav1.OwnerReference {
|
||||
for _, owner := range ac.GetOwnerReferences() {
|
||||
if owner.APIVersion == v1beta1.SchemeGroupVersion.String() && owner.Kind == v1beta1.ApplicationKind &&
|
||||
owner.Controller != nil && *owner.Controller {
|
||||
return metav1.NewControllerRef(ac, v1alpha2.ApplicationContextGroupVersionKind)
|
||||
}
|
||||
}
|
||||
return metav1.NewControllerRef(ac, v1alpha2.ApplicationConfigurationGroupVersionKind)
|
||||
}
|
||||
|
||||
func matchValue(conds []v1alpha2.ConditionRequirement, val string, paved, ac *fieldpath.Paved) (bool, string) {
|
||||
// If no condition is specified, it is by default to check value not empty.
|
||||
if len(conds) == 0 {
|
||||
|
||||
+26
-13
@@ -132,24 +132,37 @@ type ConditionedObject interface {
|
||||
|
||||
// LocateParentAppConfig locate the parent application configuration object
|
||||
func LocateParentAppConfig(ctx context.Context, client client.Client, oamObject oam.Object) (oam.Object, error) {
|
||||
var acName string
|
||||
var eventObj = &v1alpha2.ApplicationConfiguration{}
|
||||
|
||||
// locate the appConf name from the owner list
|
||||
for _, o := range oamObject.GetOwnerReferences() {
|
||||
if o.Kind == v1alpha2.ApplicationConfigurationKind {
|
||||
acName = o.Name
|
||||
break
|
||||
var eventObj = &v1alpha2.ApplicationConfiguration{}
|
||||
acName := o.Name
|
||||
if len(acName) > 0 {
|
||||
nn := types.NamespacedName{
|
||||
Name: acName,
|
||||
Namespace: oamObject.GetNamespace(),
|
||||
}
|
||||
if err := client.Get(ctx, nn, eventObj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eventObj, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(acName) > 0 {
|
||||
nn := types.NamespacedName{
|
||||
Name: acName,
|
||||
Namespace: oamObject.GetNamespace(),
|
||||
if o.Kind == v1alpha2.ApplicationContextKind {
|
||||
var eventObj = &v1alpha2.ApplicationContext{}
|
||||
appName := o.Name
|
||||
if len(appName) > 0 {
|
||||
nn := types.NamespacedName{
|
||||
Name: appName,
|
||||
Namespace: oamObject.GetNamespace(),
|
||||
}
|
||||
if err := client.Get(ctx, nn, eventObj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eventObj, nil
|
||||
}
|
||||
}
|
||||
if err := client.Get(ctx, nn, eventObj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eventObj, nil
|
||||
}
|
||||
return nil, errors.Errorf(ErrLocateAppConfig)
|
||||
}
|
||||
|
||||
@@ -25,11 +25,6 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -38,6 +33,12 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
)
|
||||
|
||||
var _ = Describe("Test application cross namespace resource", func() {
|
||||
@@ -240,7 +241,7 @@ var _ = Describe("Test application cross namespace resource", func() {
|
||||
return fmt.Errorf("error workload number %v", err)
|
||||
}
|
||||
workload := depolys.Items[0]
|
||||
if len(workload.OwnerReferences) != 1 || workload.OwnerReferences[0].Kind != v1alpha2.ApplicationConfigurationKind {
|
||||
if len(workload.OwnerReferences) != 1 || workload.OwnerReferences[0].Kind != v1alpha2.ApplicationContextKind {
|
||||
return fmt.Errorf("workload owneRefernece err")
|
||||
}
|
||||
err = k8sClient.Get(ctx, generateResourceTrackerKey(app.Namespace, app.Name), resourceTracker)
|
||||
@@ -485,7 +486,7 @@ var _ = Describe("Test application cross namespace resource", func() {
|
||||
return fmt.Errorf("failed generate same namespace workload")
|
||||
}
|
||||
sameDeplpoy := same.Items[0]
|
||||
if len(sameDeplpoy.OwnerReferences) != 1 || sameDeplpoy.OwnerReferences[0].Kind != v1alpha2.ApplicationConfigurationKind {
|
||||
if len(sameDeplpoy.OwnerReferences) != 1 || sameDeplpoy.OwnerReferences[0].Kind != v1alpha2.ApplicationContextKind {
|
||||
return fmt.Errorf("same ns deploy have error ownerReference")
|
||||
}
|
||||
err = k8sClient.List(ctx, cross, crossOpts...)
|
||||
@@ -538,7 +539,7 @@ var _ = Describe("Test application cross namespace resource", func() {
|
||||
return fmt.Errorf("failed generate same namespace workload")
|
||||
}
|
||||
sameDeplpoy := same.Items[0]
|
||||
if len(sameDeplpoy.OwnerReferences) != 1 || sameDeplpoy.OwnerReferences[0].Kind != v1alpha2.ApplicationConfigurationKind {
|
||||
if len(sameDeplpoy.OwnerReferences) != 1 || sameDeplpoy.OwnerReferences[0].Kind != v1alpha2.ApplicationContextKind {
|
||||
return fmt.Errorf("same ns deploy have error ownerReference")
|
||||
}
|
||||
err = k8sClient.List(ctx, cross, crossOpts...)
|
||||
|
||||
@@ -106,7 +106,7 @@ var _ = Describe("Application Normal tests", func() {
|
||||
|
||||
verifyWorkloadRunningExpected := func(workloadName string, replicas int32, image string) {
|
||||
var workload v1.Deployment
|
||||
By("Verify AppConfig is inactive")
|
||||
By("Verify Workload running as expected")
|
||||
Eventually(
|
||||
func() error {
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Namespace: namespaceName, Name: workloadName}, &workload); err != nil {
|
||||
|
||||
@@ -182,7 +182,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
}
|
||||
return ""
|
||||
},
|
||||
time.Second*30, time.Millisecond*500).Should(BeEquivalentTo(v1alpha2.ApplicationConfigurationKind))
|
||||
time.Second*30, time.Millisecond*500).Should(BeEquivalentTo(v1alpha2.ApplicationContextKind))
|
||||
Expect(clonesetOwner.Name).Should(BeEquivalentTo(targetAppName))
|
||||
Expect(kc.Status.UpdatedReplicas).Should(BeEquivalentTo(*kc.Spec.Replicas))
|
||||
Expect(kc.Status.UpdatedReadyReplicas).Should(BeEquivalentTo(*kc.Spec.Replicas))
|
||||
|
||||
Reference in New Issue
Block a user