Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve/NiFiCluster] Move from volume prefix to pvc label selection for deletion #146

Merged
merged 7 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Changed

- [PR #146](https://github.com/konpyutaika/nifikop/pull/146) - **[Operator/NifiCluster]** Move from volume prefix to pvc label selection for deletion

### Deprecated

### Removed
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 @@ -237,6 +237,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
14 changes: 13 additions & 1 deletion pkg/resources/nifi/nifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,19 @@ OUTERLOOP:
}

for _, volume := range node.Spec.Volumes {
if strings.HasPrefix(volume.Name, nifiutil.NifiDataVolumeMount) {
if volume.PersistentVolumeClaim == nil {
continue
}
pvcFound := &corev1.PersistentVolumeClaim{}
r.Client.Get(context.TODO(),
erdrix marked this conversation as resolved.
Show resolved Hide resolved
types.NamespacedName{
Name: volume.PersistentVolumeClaim.ClaimName,
Namespace: r.NifiCluster.Namespace,
},
pvcFound,
)

if pvcFound.Labels[nifiutil.NifiDataVolumeMountKey] == "true" {
erdrix marked this conversation as resolved.
Show resolved Hide resolved
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"
)
4 changes: 2 additions & 2 deletions pkg/util/nifi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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"
NifiDataVolumeMountKey = "nifi-data"
erdrix marked this conversation as resolved.
Show resolved Hide resolved
)

// ParseTimeStampToUnixTime parses the given CC timeStamp to time format
Expand Down