use AppContext as the ownerRef

This commit is contained in:
天元
2021-03-30 00:21:17 +08:00
parent 4918b5cee7
commit 72f533e5eb
5 changed files with 7 additions and 14 deletions
@@ -818,13 +818,13 @@ func isControlledByApp(ac *v1alpha2.ApplicationConfiguration) bool {
return false
}
// getOwnerFromAC will check and get the real owner, if the owner is Application, it will use Application as owner
// 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 &owner
return metav1.NewControllerRef(ac, v1alpha2.ApplicationContextGroupVersionKind)
}
}
return metav1.NewControllerRef(ac, v1alpha2.ApplicationConfigurationGroupVersionKind)
@@ -102,13 +102,6 @@ func (r *Reconciler) Reconcile(request reconcile.Request) (reconcile.Result, err
// the name of the appConfig has to be the same as the appContext
appConfig.Name = appContext.Name
appConfig.UID = appContext.UID
for _, owner := range appContext.GetOwnerReferences() {
// if the appContext is created by Application, set the AppConfig UID to align with the application
if owner.Kind == v1beta1.ApplicationKind {
appConfig.UID = owner.UID
break
}
}
appConfig.SetLabels(appContext.GetLabels())
appConfig.SetAnnotations(appContext.GetAnnotations())
// makes sure that the appConfig's owner is the same as the appContext
+1 -1
View File
@@ -152,7 +152,7 @@ func LocateParentAppConfig(ctx context.Context, client client.Client, oamObject
}
}
if o.Kind == v1beta1.ApplicationKind {
var eventObj = &v1beta1.Application{}
var eventObj = &v1alpha2.ApplicationContext{}
appName := o.Name
if len(appName) > 0 {
nn := types.NamespacedName{
+3 -3
View File
@@ -241,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 != v1beta1.ApplicationKind {
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)
@@ -486,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 != v1beta1.ApplicationKind {
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...)
@@ -539,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 != v1beta1.ApplicationKind {
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...)
+1 -1
View File
@@ -182,7 +182,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
}
return ""
},
time.Second*30, time.Millisecond*500).Should(BeEquivalentTo(v1beta1.ApplicationKind))
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))