diff --git a/deploy/operator.yaml b/deploy/operator.yaml index f43422e17..ad2f56afe 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -16,7 +16,7 @@ spec: containers: - name: kubeflow-operator # Replace this with the built image name - image: aipipeline/kubeflow-operator:v1.1.0 + image: aipipeline/kubeflow-operator:latest command: - kfctl imagePullPolicy: Always diff --git a/pkg/controller/kfdef/kfdef_controller.go b/pkg/controller/kfdef/kfdef_controller.go index f4969aeae..0186d25b6 100644 --- a/pkg/controller/kfdef/kfdef_controller.go +++ b/pkg/controller/kfdef/kfdef_controller.go @@ -175,7 +175,20 @@ var kfdefPredicates = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { object, _ := meta.Accessor(e.ObjectOld) log.Infof("Got update event for %v.%v.", object.GetName(), object.GetNamespace()) - return true + + upd, _ := meta.Accessor(e.ObjectNew) + // these cases will result in a reconcile request + // 1. the finalizer is added 2. the deletiontimestamp is added 3. generation is increased + if len(object.GetFinalizers()) == 0 && len(upd.GetFinalizers()) > 0 { + return true + } + if object.GetDeletionTimestamp() == nil && upd.GetDeletionTimestamp() != nil { + return true + } + if upd.GetGeneration() > object.GetGeneration() { + return true + } + return false }, } diff --git a/pkg/kfapp/kustomize/kustomize.go b/pkg/kfapp/kustomize/kustomize.go index b4d697306..441abd5e9 100644 --- a/pkg/kfapp/kustomize/kustomize.go +++ b/pkg/kfapp/kustomize/kustomize.go @@ -1392,7 +1392,6 @@ func CreateKustomizationMaps() map[MapType]map[string]bool { // GenerateYamlWithOperatorAnnotation adds operator info to the annotation to every resource // some code copied from ResMap.AsYaml() func func GenerateYamlWithOperatorAnnotation(resMap resmap.ResMap, instance *unstructured.Unstructured) ([]byte, error) { - addAnnotation := true firstObj := true var b []byte buf := bytes.NewBuffer(b) @@ -1413,6 +1412,7 @@ func GenerateYamlWithOperatorAnnotation(resMap resmap.ResMap, instance *unstruct kfdefAnn := strings.Join([]string{utils.KfDefAnnotation, utils.KfDefInstance}, "/") kfdefCr := strings.Join([]string{instance.GetName(), instance.GetNamespace()}, ".") + addAnnotation := true if m.GetKind() == "Namespace" { config, _ := rest.InClusterConfig() corev1client, err := corev1.NewForConfig(config) @@ -1422,14 +1422,19 @@ func GenerateYamlWithOperatorAnnotation(resMap resmap.ResMap, instance *unstruct Message: fmt.Sprintf("failed to create corev1 client: %v", err), } } - _, err = corev1client.Namespaces().Get(m.GetName(), metav1.GetOptions{}) + ns, err := corev1client.Namespaces().Get(m.GetName(), metav1.GetOptions{}) if err == nil { log.Infof("Namespace %v already exists.", m.GetName()) - _, found := anns[kfdefAnn] - if !found || anns[kfdefAnn] != kfdefCr { - // if the namespace is not created by this operator, should not append the annotation + nsAnns := ns.GetAnnotations() + if nsAnns == nil { addAnnotation = false + } else { + _, found := nsAnns[kfdefAnn] + if !found || nsAnns[kfdefAnn] != kfdefCr { + // if the namespace is not created by this operator, should not append the annotation + addAnnotation = false + } } } } else if m.GetKind() == "CustomResourceDefinition" && m.GetName() == "profiles.kubeflow.org" {