Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

added labels to nodeConfig and pod policy #150

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -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
Expand Down
12 changes: 11 additions & 1 deletion api/v1alpha1/nificluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Copy link
Contributor Author

@mh013370 mh013370 Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered & fixed a bug where NodeAnnotations was documented as nodeAnnotations in the NiFiCluster CRD . However, it was nifiAnnotations in the actual custom resource definition. I've renamed it here (and it's reflected in the CRD) to match the documentation. This is technically an API breaking change, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #151 to cover this issue

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
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 30 additions & 12 deletions config/crd/bases/nifi.orange.com_nificlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions config/samples/simplenificluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ metadata:
spec:
service:
headlessEnabled: true
pod:
labels:
pod-label: "pod-label-value"
zkAddress: "zookeeper.dlice:2181"
zkPath: "/simplenifi"
clusterImage: "apache/nifi:1.12.1"
oneNifiNodePerNode: false
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
Expand Down
42 changes: 30 additions & 12 deletions helm/nifikop/crds/nifi.orange.com_nificlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions pkg/resources/nifi/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand All @@ -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{
Expand Down
1 change: 1 addition & 0 deletions site/docs/5_references/1_nifi_cluster/1_nifi_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions site/docs/5_references/1_nifi_cluster/3_node_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down