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