Skip to content

Commit

Permalink
[Improve/NiFiCluster] Move from volume prefix to pvc label selection …
Browse files Browse the repository at this point in the history
…for deletion (#146)

* move from volume prefix to pvc label selection

* append changelog

* clean documentation

* more specific labels for pvc & catch get pvc error
  • Loading branch information
erdrix authored Aug 25, 2022
1 parent 7f555fe commit 8874319
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions config/samples/nifi_v1alpha1_nificluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions controllers/nifinodegroupautoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion pkg/resources/nifi/nifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions pkg/resources/nifi/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 0 additions & 1 deletion pkg/resources/templates/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package templates

const (
NodeConfigTemplate = "%s-config"
StorageNameTemplate = "%s-%s"
NodeStorageTemplate = "%s-%d-%s-storage-"
ExternalClusterSecretTemplate = "%s-basic-secret"
)
7 changes: 5 additions & 2 deletions pkg/util/nifi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8874319

Please sign in to comment.