diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c277c59c2..3530a4f914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Changed +- [PR #146](https://github.com/konpyutaika/nifikop/pull/146) - **[Operator/NifiCluster]** Move from volume prefix to pvc label selection for deletion - [PR #142](https://github.com/konpyutaika/nifikop/pull/142) - **[Operator]** Fixed issue where operator would modify `NifiCluster` and `NifiDataflow` status on every reconciliation loop unnecessarily. - [PR #151](https://github.com/konpyutaika/nifikop/pull/151) - **[Operator]** Fixed an issue where the controller logging erroneously appeared to all come from the same controller. diff --git a/config/samples/nifi_v1alpha1_nificluster.yaml b/config/samples/nifi_v1alpha1_nificluster.yaml index a4e7786da7..aab9db038a 100644 --- a/config/samples/nifi_v1alpha1_nificluster.yaml +++ b/config/samples/nifi_v1alpha1_nificluster.yaml @@ -34,9 +34,9 @@ spec: # imagePullPolicy: IfNotPresent # command: ["sh", "-c", "cp -vr /nifi_lib/* /nifi_lib_volume/"] # volumeMounts: - # - name: nifi-data-extensions-repository + # - name: extensions-repository # mountPath: /nifi_lib_volume - # - name: nifi-data-logs + # - name: logs # mountPath: /logs # clusterImage can specify the whole nificluster image in one place clusterImage: "apache/nifi:1.12.1" diff --git a/controllers/nifinodegroupautoscaler_controller.go b/controllers/nifinodegroupautoscaler_controller.go index 3b205bb88c..8e38c39166 100644 --- a/controllers/nifinodegroupautoscaler_controller.go +++ b/controllers/nifinodegroupautoscaler_controller.go @@ -238,6 +238,7 @@ func (r *NifiNodeGroupAutoscalerReconciler) updateAutoscalerReplicaState(ctx con return r.Client.Status().Update(ctx, autoscaler) } +// TODO : discuss about replacing by looking for NifiCluster.Spec.Nodes instead // updateAutoscalerReplicaStatus updates autoscaler replica status to inform the k8s scale subresource func (r *NifiNodeGroupAutoscalerReconciler) updateAutoscalerReplicaStatus(ctx context.Context, nifiCluster *v1alpha1.NifiCluster, autoscaler *v1alpha1.NifiNodeGroupAutoscaler) error { podList, err := r.getCurrentReplicaPods(ctx, autoscaler) diff --git a/pkg/resources/nifi/nifi.go b/pkg/resources/nifi/nifi.go index 749792519c..c423190f5a 100644 --- a/pkg/resources/nifi/nifi.go +++ b/pkg/resources/nifi/nifi.go @@ -344,7 +344,24 @@ OUTERLOOP: } for _, volume := range node.Spec.Volumes { - if strings.HasPrefix(volume.Name, nifiutil.NifiDataVolumeMount) { + if volume.PersistentVolumeClaim == nil { + continue + } + pvcFound := &corev1.PersistentVolumeClaim{} + if err := r.Client.Get(context.TODO(), + types.NamespacedName{ + Name: volume.PersistentVolumeClaim.ClaimName, + Namespace: r.NifiCluster.Namespace, + }, + pvcFound, + ); err != nil { + if apierrors.IsNotFound(err) { + continue + } + return errors.WrapIfWithDetails(err, "could not get pvc for node", "id", node.Labels["nodeId"]) + } + + if pvcFound.Labels[nifiutil.NifiDataVolumeMountKey] == "true" { err = r.Client.Delete(context.TODO(), &corev1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{ Name: volume.PersistentVolumeClaim.ClaimName, Namespace: r.NifiCluster.Namespace, diff --git a/pkg/resources/nifi/pvc.go b/pkg/resources/nifi/pvc.go index 2ecd5e63f2..90c42db0bd 100644 --- a/pkg/resources/nifi/pvc.go +++ b/pkg/resources/nifi/pvc.go @@ -19,11 +19,12 @@ func (r *Reconciler) pvc(id int32, storage v1alpha1.StorageConfig, log zap.Logge util.MergeLabels( nifiutil.LabelsForNifi(r.NifiCluster.Name), map[string]string{ - "nodeId": fmt.Sprintf("%d", id), - "storageName": storage.Name, + "nodeId": fmt.Sprintf("%d", id), + "storageName": storage.Name, + nifiutil.NifiDataVolumeMountKey: "true", }, ), - map[string]string{"mountPath": storage.MountPath, "storageName": fmt.Sprintf(templates.StorageNameTemplate, nifiutil.NifiDataVolumeMount, storage.Name)}, r.NifiCluster), + map[string]string{"mountPath": storage.MountPath, "storageName": storage.Name}, r.NifiCluster), Spec: *storage.PVCSpec, } } diff --git a/pkg/resources/templates/variables.go b/pkg/resources/templates/variables.go index 763e106655..249c1f2e17 100644 --- a/pkg/resources/templates/variables.go +++ b/pkg/resources/templates/variables.go @@ -2,7 +2,6 @@ package templates const ( NodeConfigTemplate = "%s-config" - StorageNameTemplate = "%s-%s" NodeStorageTemplate = "%s-%d-%s-storage-" ExternalClusterSecretTemplate = "%s-basic-secret" ) diff --git a/pkg/util/nifi/common.go b/pkg/util/nifi/common.go index 2cabfd6da4..238a2aa4ac 100644 --- a/pkg/util/nifi/common.go +++ b/pkg/util/nifi/common.go @@ -15,8 +15,11 @@ const ( NodeNameTemplate = PrefixNodeNameTemplate + RootNodeNameTemplate + SuffixNodeNameTemplate // TimeStampLayout defines the date format used. - TimeStampLayout = "Mon, 2 Jan 2006 15:04:05 GMT" - NifiDataVolumeMount = "nifi-data" + TimeStampLayout = "Mon, 2 Jan 2006 15:04:05 GMT" +) + +var ( + NifiDataVolumeMountKey = fmt.Sprintf("%s/nifi-data", v1alpha1.GroupVersion.Group) ) // ParseTimeStampToUnixTime parses the given CC timeStamp to time format