From 8edda93dc0fc986511e9b7e514ddbb9801026058 Mon Sep 17 00:00:00 2001 From: Michael H Date: Thu, 4 Nov 2021 10:13:33 +0000 Subject: [PATCH 1/2] added labels to nodeConfig and pod policy fix mismatched nodeAnnotations and nifiAnnotations, renamed incorrect nifiLabels to nodeLabels fix wrong text Signed-off-by: Michael H updated changelog Signed-off-by: Michael H --- CHANGELOG.md | 2 + api/v1alpha1/nificluster_types.go | 12 +++++- api/v1alpha1/zz_generated.deepcopy.go | 14 +++++++ .../bases/nifi.orange.com_nificlusters.yaml | 42 +++++++++++++------ config/samples/simplenificluster.yaml | 7 ++++ pkg/resources/nifi/pod.go | 12 ++++-- .../1_nifi_cluster/1_nifi_cluster.md | 1 + .../1_nifi_cluster/3_node_config.md | 1 + 8 files changed, 74 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 525da155e..12601c091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Added +- [PR #150](https://github.com/Orange-OpenSource/nifikop/pull/150) - **[Operator/NiFiCluster]** Added labels to nodeConfig and pod policy. + ### Changed ### Deprecated diff --git a/api/v1alpha1/nificluster_types.go b/api/v1alpha1/nificluster_types.go index afb711dd8..6c1dab693 100644 --- a/api/v1alpha1/nificluster_types.go +++ b/api/v1alpha1/nificluster_types.go @@ -126,6 +126,8 @@ type ServicePolicy struct { type PodPolicy struct { // Annotations specifies the annotations to attach to pods the operator creates Annotations map[string]string `json:"annotations,omitempty"` + // Labels specifies additional labels to attach to the pods the operator creates + Labels map[string]string `json:"labels,omitempty"` } // rollingUpgradeConfig specifies the rolling upgrade config for the cluster @@ -281,7 +283,10 @@ type NodeConfig struct { Tolerations []corev1.Toleration `json:"tolerations,omitempty"` // Additionnal annotation to attach to the pod associated // https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set - NodeAnnotations map[string]string `json:"nifiAnnotations,omitempty"` + NodeAnnotations map[string]string `json:"nodeAnnotations,omitempty"` + // Additionnal labels to attach to the pod associated + // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set + NodeLabels map[string]string `json:"nodeLabels,omitempty"` } // StorageConfig defines the node storage configuration @@ -592,6 +597,11 @@ func (nConfig *NodeConfig) GetNodeAnnotations() map[string]string { return nConfig.NodeAnnotations } +// GetNodeLabels returns additional labels configured to be applied to each nifi node +func (nConfig *NodeConfig) GetNodeLabels() map[string]string { + return nConfig.NodeLabels +} + // GetResources returns the nifi node specific Kubernetes resource func (nConfig *NodeConfig) GetResources() *corev1.ResourceRequirements { if nConfig.ResourcesRequirements != nil { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 184e448ac..7db42063a 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1152,6 +1152,13 @@ func (in *NodeConfig) DeepCopyInto(out *NodeConfig) { (*out)[key] = val } } + if in.NodeLabels != nil { + in, out := &in.NodeLabels, &out.NodeLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeConfig. @@ -1240,6 +1247,13 @@ func (in *PodPolicy) DeepCopyInto(out *PodPolicy) { (*out)[key] = val } } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodPolicy. diff --git a/config/crd/bases/nifi.orange.com_nificlusters.yaml b/config/crd/bases/nifi.orange.com_nificlusters.yaml index b46ff8a28..18827f36e 100644 --- a/config/crd/bases/nifi.orange.com_nificlusters.yaml +++ b/config/crd/bases/nifi.orange.com_nificlusters.yaml @@ -1461,12 +1461,6 @@ spec: description: Set this to true if the instance is a node in a cluster. https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#basic-cluster-setup type: boolean - nifiAnnotations: - additionalProperties: - type: string - description: Additionnal annotation to attach to the pod associated - https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set - type: object nodeAffinity: description: nodeAffinity can be specified, operator populates this value if new pvc added later to node @@ -1672,6 +1666,18 @@ spec: - nodeSelectorTerms type: object type: object + nodeAnnotations: + additionalProperties: + type: string + description: Additionnal annotation to attach to the pod associated + https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set + type: object + nodeLabels: + additionalProperties: + type: string + description: Additionnal labels to attach to the pod associated + https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set + type: object nodeSelector: additionalProperties: type: string @@ -1969,12 +1975,6 @@ spec: description: Set this to true if the instance is a node in a cluster. https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#basic-cluster-setup type: boolean - nifiAnnotations: - additionalProperties: - type: string - description: Additionnal annotation to attach to the pod - associated https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set - type: object nodeAffinity: description: nodeAffinity can be specified, operator populates this value if new pvc added later to node @@ -2189,6 +2189,18 @@ spec: - nodeSelectorTerms type: object type: object + nodeAnnotations: + additionalProperties: + type: string + description: Additionnal annotation to attach to the pod + associated https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set + type: object + nodeLabels: + additionalProperties: + type: string + description: Additionnal labels to attach to the pod associated + https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set + type: object nodeSelector: additionalProperties: type: string @@ -2860,6 +2872,12 @@ spec: description: Annotations specifies the annotations to attach to pods the operator creates type: object + labels: + additionalProperties: + type: string + description: Labels specifies additional labels to attach to the + pods the operator creates + type: object type: object propagateLabels: description: propage diff --git a/config/samples/simplenificluster.yaml b/config/samples/simplenificluster.yaml index 82e0b22b1..d2bbe44ed 100644 --- a/config/samples/simplenificluster.yaml +++ b/config/samples/simplenificluster.yaml @@ -5,6 +5,9 @@ metadata: spec: service: headlessEnabled: true + pod: + labels: + pod-label: "pod-label-value" zkAddress: "zookeeper.dlice:2181" zkPath: "/simplenifi" clusterImage: "apache/nifi:1.12.1" @@ -12,6 +15,10 @@ spec: nodeConfigGroups: default_group: isNode: true + nodeAnnotations: + node-annotation: "node-annotation-value" + nodeLabels: + node-label: "node-label-value" storageConfigs: - mountPath: "/opt/nifi/nifi-current/logs" name: logs diff --git a/pkg/resources/nifi/pod.go b/pkg/resources/nifi/pod.go index 0a9bb1db0..3e4fb0bff 100644 --- a/pkg/resources/nifi/pod.go +++ b/pkg/resources/nifi/pod.go @@ -121,6 +121,13 @@ func (r *Reconciler) pod(id int32, nodeConfig *v1alpha1.NodeConfig, pvcs []corev r.NifiCluster.Spec.Pod.Annotations, } + labelsToMerge := []map[string]string{ + nifiutil.LabelsForNifi(r.NifiCluster.Name), + nodeConfig.GetNodeLabels(), + r.NifiCluster.Spec.Pod.Labels, + {"nodeId": fmt.Sprintf("%d", id)}, + } + if r.NifiCluster.Spec.GetMetricPort() != nil { anntotationsToMerge = append(anntotationsToMerge, util.MonitoringAnnotations(*r.NifiCluster.Spec.GetMetricPort())) } @@ -132,10 +139,7 @@ func (r *Reconciler) pod(id int32, nodeConfig *v1alpha1.NodeConfig, pvcs []corev //ObjectMeta: templates.ObjectMetaWithAnnotations( ObjectMeta: templates.ObjectMetaWithGeneratedNameAndAnnotations( nifiutil.ComputeNodeName(id, r.NifiCluster.Name), - util.MergeLabels( - nifiutil.LabelsForNifi(r.NifiCluster.Name), - map[string]string{"nodeId": fmt.Sprintf("%d", id)}, - ), + util.MergeLabels(labelsToMerge...), util.MergeAnnotations(anntotationsToMerge...), r.NifiCluster, ), Spec: corev1.PodSpec{ diff --git a/site/docs/5_references/1_nifi_cluster/1_nifi_cluster.md b/site/docs/5_references/1_nifi_cluster/1_nifi_cluster.md index 6d0021eca..3aa0c2aaf 100644 --- a/site/docs/5_references/1_nifi_cluster/1_nifi_cluster.md +++ b/site/docs/5_references/1_nifi_cluster/1_nifi_cluster.md @@ -129,6 +129,7 @@ spec: | Field | Type | Description | Required | Default | | ----------- | ------------------- | ------------------------------------------------------------------------------------ | -------- | ------- | | annotations | map\[string\]string | Annotations specifies the annotations to attach to pods the NiFiKop operator creates | No | - | +| labels | map\[string\]string | Labels specifies the labels to attach to pods the NiFiKop operator creates | No | - | ## ManagedUsers diff --git a/site/docs/5_references/1_nifi_cluster/3_node_config.md b/site/docs/5_references/1_nifi_cluster/3_node_config.md index 065ea4d58..7b1070a2a 100644 --- a/site/docs/5_references/1_nifi_cluster/3_node_config.md +++ b/site/docs/5_references/1_nifi_cluster/3_node_config.md @@ -69,6 +69,7 @@ NodeConfig defines the node configuration |nodeSelector|map\[string\]string|nodeSelector can be specified, which set the pod to fit on a node [nodeselector](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector)|No|nil| |tolerations|\[ \][Toleration](https://godoc.org/k8s.io/api/core/v1#Toleration)|tolerations can be specified, which set the pod's tolerations [taint-and-toleration](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/#concepts).|No|nil| |nodeAnnotations|map\[string\]string|Additionnal annotation to attach to the pod associated [annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set).|No|nil| +|nodeLabels|map\[string\]string|Additionnal labels to attach to the pod associated [labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set).|No|nil| ## StorageConfig From 177d6e3424d40de5c35eb1d8df5773448cd86ebf Mon Sep 17 00:00:00 2001 From: Michael H Date: Thu, 3 Mar 2022 15:47:43 +0000 Subject: [PATCH 2/2] update helm CRDs Signed-off-by: Michael H --- .../crds/nifi.orange.com_nificlusters.yaml | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/helm/nifikop/crds/nifi.orange.com_nificlusters.yaml b/helm/nifikop/crds/nifi.orange.com_nificlusters.yaml index b46ff8a28..18827f36e 100644 --- a/helm/nifikop/crds/nifi.orange.com_nificlusters.yaml +++ b/helm/nifikop/crds/nifi.orange.com_nificlusters.yaml @@ -1461,12 +1461,6 @@ spec: description: Set this to true if the instance is a node in a cluster. https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#basic-cluster-setup type: boolean - nifiAnnotations: - additionalProperties: - type: string - description: Additionnal annotation to attach to the pod associated - https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set - type: object nodeAffinity: description: nodeAffinity can be specified, operator populates this value if new pvc added later to node @@ -1672,6 +1666,18 @@ spec: - nodeSelectorTerms type: object type: object + nodeAnnotations: + additionalProperties: + type: string + description: Additionnal annotation to attach to the pod associated + https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set + type: object + nodeLabels: + additionalProperties: + type: string + description: Additionnal labels to attach to the pod associated + https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set + type: object nodeSelector: additionalProperties: type: string @@ -1969,12 +1975,6 @@ spec: description: Set this to true if the instance is a node in a cluster. https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#basic-cluster-setup type: boolean - nifiAnnotations: - additionalProperties: - type: string - description: Additionnal annotation to attach to the pod - associated https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set - type: object nodeAffinity: description: nodeAffinity can be specified, operator populates this value if new pvc added later to node @@ -2189,6 +2189,18 @@ spec: - nodeSelectorTerms type: object type: object + nodeAnnotations: + additionalProperties: + type: string + description: Additionnal annotation to attach to the pod + associated https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set + type: object + nodeLabels: + additionalProperties: + type: string + description: Additionnal labels to attach to the pod associated + https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set + type: object nodeSelector: additionalProperties: type: string @@ -2860,6 +2872,12 @@ spec: description: Annotations specifies the annotations to attach to pods the operator creates type: object + labels: + additionalProperties: + type: string + description: Labels specifies additional labels to attach to the + pods the operator creates + type: object type: object propagateLabels: description: propage