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

Commit

Permalink
[Operator/ParameterContext] Support empty string and no value set (#144)
Browse files Browse the repository at this point in the history
* add feature and bump version

* append changelog
  • Loading branch information
erdrix authored Oct 26, 2021
1 parent de8cd00 commit 4502cc0
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 56 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

### Fixed Bugs

## v0.7.1

### Added

- [PR #144](https://github.com/Orange-OpenSource/nifikop/pull/144) - **[Operator/Parameter]** Support empty string and no value set.

## v0.7.0

### Added
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func SecretRefsEquals(secretRefs []SecretReference) bool {
type DataflowSyncMode string

const (
SyncNever DataflowSyncMode = "never"
SyncOnce DataflowSyncMode = "once"
SyncNever DataflowSyncMode = "never"
SyncOnce DataflowSyncMode = "once"
SyncAlways DataflowSyncMode = "always"
)
2 changes: 1 addition & 1 deletion api/v1alpha1/nifiparametercontext_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Parameter struct {
// the name of the Parameter.
Name string `json:"name"`
// the value of the Parameter.
Value string `json:"value,omitempty"`
Value *string `json:"value,omitempty"`
// the description of the Parameter.
Description string `json:"description,omitempty"`
}
Expand Down
9 changes: 8 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
- /manager
args:
- --leader-elect
image: orangeopensource/nifikop:v0.7.0-release
image: orangeopensource/nifikop:v0.7.1-release
name: nifikop
securityContext:
allowPrivilegeEscalation: false
Expand Down
14 changes: 7 additions & 7 deletions controllers/nifidataflow_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (r *NifiDataflowReconciler) Reconcile(ctx context.Context, req ctrl.Request
if k8sutil.IsMarkedForDeletion(instance.ObjectMeta) {
r.Log.Info("Cluster is already gone, there is nothing we can do")
if err = r.removeFinalizer(ctx, instance); err != nil {
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return Reconciled()
}

Expand All @@ -204,13 +204,13 @@ func (r *NifiDataflowReconciler) Reconcile(ctx context.Context, req ctrl.Request
return RequeueWithError(r.Log, "could not apply last state to annotation", err)
}
if err := r.Client.Update(ctx, current); err != nil {
return RequeueWithError(r.Log, "failed to update NifiDataflow", err)
}
return RequeueAfter(time.Duration(15) * time.Second)
return RequeueWithError(r.Log, "failed to update NifiDataflow", err)
}
return RequeueAfter(time.Duration(15) * time.Second)
}
r.Recorder.Event(instance, corev1.EventTypeWarning, "ReferenceClusterError",
fmt.Sprintf("Failed to lookup reference cluster : %s in %s",
instance.Spec.ClusterRef.Name, currentClusterRef.Namespace))
instance.Spec.ClusterRef.Name, currentClusterRef.Namespace))

// the cluster does not exist - should have been caught pre-flight
return RequeueWithError(r.Log, "failed to lookup referenced cluster", err)
Expand Down Expand Up @@ -320,7 +320,7 @@ func (r *NifiDataflowReconciler) Reconcile(ctx context.Context, req ctrl.Request
return RequeueWithError(r.Log, "failed to update NifiDataflow", err)
}

if instance.Spec.SyncNever(){
if instance.Spec.SyncNever() {
return Reconciled()
}

Expand Down
9 changes: 4 additions & 5 deletions controllers/nifiparametercontext_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ func (r *NifiParameterContextReconciler) Reconcile(ctx context.Context, req ctrl

// Generate the connect object
if clusterConnect, err = configManager.BuildConnect(); err != nil {
// This shouldn't trigger anymore, but leaving it here as a safetybelt
// This shouldn't trigger anymore, but leaving it here as a safetybelt
if k8sutil.IsMarkedForDeletion(instance.ObjectMeta) {
r.Log.Info("Cluster is already gone, there is nothing we can do")
if err = r.removeFinalizer(ctx, instance); err != nil {
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return Reconciled()
}
// If the referenced cluster no more exist, just skip the deletion requirement in cluster ref change case.
Expand All @@ -156,13 +156,12 @@ func (r *NifiParameterContextReconciler) Reconcile(ctx context.Context, req ctrl

r.Recorder.Event(instance, corev1.EventTypeWarning, "ReferenceClusterError",
fmt.Sprintf("Failed to lookup reference cluster : %s in %s",
instance.Spec.ClusterRef.Name, clusterRef.Namespace))
instance.Spec.ClusterRef.Name, clusterRef.Namespace))

// the cluster does not exist - should have been caught pre-flight
return RequeueWithError(r.Log, "failed to lookup referenced cluster", err)
}


// Generate the client configuration.
clientConfig, err = configManager.BuildConfig()
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions controllers/nifiregistryclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (r *NifiRegistryClientReconciler) Reconcile(ctx context.Context, req ctrl.R
if k8sutil.IsMarkedForDeletion(instance.ObjectMeta) {
r.Log.Info("Cluster is already gone, there is nothing we can do")
if err = r.removeFinalizer(ctx, instance); err != nil {
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return Reconciled()
}
// If the referenced cluster no more exist, just skip the deletion requirement in cluster ref change case.
Expand All @@ -133,12 +133,11 @@ func (r *NifiRegistryClientReconciler) Reconcile(ctx context.Context, req ctrl.R

r.Recorder.Event(instance, corev1.EventTypeWarning, "ReferenceClusterError",
fmt.Sprintf("Failed to lookup reference cluster : %s in %s",
instance.Spec.ClusterRef.Name, clusterRef.Namespace))
instance.Spec.ClusterRef.Name, clusterRef.Namespace))
// the cluster does not exist - should have been caught pre-flight
return RequeueWithError(r.Log, "failed to lookup referenced cluster", err)
}


// Generate the client configuration.
clientConfig, err = configManager.BuildConfig()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions controllers/nifiuser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func (r *NifiUserReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return RequeueWithError(r.Log, "could not apply last state to annotation", err)
}
if err := r.Client.Update(ctx, current); err != nil {
return RequeueWithError(r.Log, "failed to update NifiUser", err)
}
return RequeueWithError(r.Log, "failed to update NifiUser", err)
}
return RequeueAfter(time.Duration(15) * time.Second)
}

r.Recorder.Event(instance, corev1.EventTypeWarning, "ReferenceClusterError",
fmt.Sprintf("Failed to lookup reference cluster : %s in %s",
instance.Spec.ClusterRef.Name, clusterRef.Namespace))
instance.Spec.ClusterRef.Name, clusterRef.Namespace))
return RequeueWithError(r.Log, "failed to lookup referenced cluster", err)
}

Expand All @@ -158,7 +158,7 @@ func (r *NifiUserReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

if v1alpha1.ClusterRefsEquals([]v1alpha1.ClusterReference{instance.Spec.ClusterRef, current.Spec.ClusterRef}) &&
instance.Spec.GetCreateCert() && !clusterConnect.IsExternal(){
instance.Spec.GetCreateCert() && !clusterConnect.IsExternal() {

// Avoid panic if the user wants to create a nifi user but the cluster is in plaintext mode
// TODO: refactor this and use webhook to validate if the cluster is eligible to create a nifi user
Expand Down
12 changes: 6 additions & 6 deletions controllers/nifiusergroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (r *NifiUserGroupReconciler) Reconcile(ctx context.Context, req ctrl.Reques
if k8sutil.IsMarkedForDeletion(instance.ObjectMeta) {
r.Log.Info("Cluster is already gone, there is nothing we can do")
if err = r.removeFinalizer(ctx, instance); err != nil {
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return RequeueWithError(r.Log, "failed to remove finalizer", err)
}
return Reconciled()
}

Expand All @@ -167,14 +167,14 @@ func (r *NifiUserGroupReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return RequeueWithError(r.Log, "could not apply last state to annotation", err)
}
if err := r.Client.Update(ctx, current); err != nil {
return RequeueWithError(r.Log, "failed to update NifiDataflow", err)
}
return RequeueAfter(time.Duration(15) * time.Second)
return RequeueWithError(r.Log, "failed to update NifiDataflow", err)
}
return RequeueAfter(time.Duration(15) * time.Second)
}

r.Recorder.Event(instance, corev1.EventTypeWarning, "ReferenceClusterError",
fmt.Sprintf("Failed to lookup reference cluster : %s in %s",
instance.Spec.ClusterRef.Name, clusterRef.Namespace))
instance.Spec.ClusterRef.Name, clusterRef.Namespace))

// the cluster does not exist - should have been caught pre-flight
return RequeueWithError(r.Log, "failed to lookup referenced cluster", err)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ require (
github.com/antihax/optional v1.0.0
github.com/banzaicloud/k8s-objectmatcher v1.4.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/erdrix/nigoapi v0.0.0-20210322100900-9bf87aec43d9
// github.com/erdrix/nigoapi v0.0.0-20210301104455-ab202e217b78
github.com/erdrix/nigoapi v0.0.0-20211026131235-b258e0b217af
github.com/go-logr/logr v0.3.0
github.com/imdario/mergo v0.3.10
github.com/jarcoal/httpmock v1.0.6
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,16 @@ github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erdrix/nigoapi v0.0.0-20210322100900-9bf87aec43d9 h1:yqGp8oivds/3m/9BT93zhEN+WvWSMJS5AClOoeVeeAs=
github.com/erdrix/nigoapi v0.0.0-20210322100900-9bf87aec43d9/go.mod h1:owY+8fs8YXnST3ENM+ulVllYjTbzGaqKA+Y7HHJ0lZA=
github.com/erdrix/nigoapi v0.0.0-20210420154406-e2cc6c207bc8 h1:i8dQxETjo7Dn+lkstq/0BwnQxhbuT63jrQNtvul1naI=
github.com/erdrix/nigoapi v0.0.0-20210420154406-e2cc6c207bc8/go.mod h1:owY+8fs8YXnST3ENM+ulVllYjTbzGaqKA+Y7HHJ0lZA=
github.com/erdrix/nigoapi v0.0.0-20211026102428-b2c05eaea34d h1:MZ+ZpxaWLA3kCt1T3KZPpN6TRrebDksfDhm8p2Qjvy8=
github.com/erdrix/nigoapi v0.0.0-20211026102428-b2c05eaea34d/go.mod h1:owY+8fs8YXnST3ENM+ulVllYjTbzGaqKA+Y7HHJ0lZA=
github.com/erdrix/nigoapi v0.0.0-20211026105001-8b40a035361c h1:/oOkNDKFoBcdNbEaI0VNsIjR/znibLb8zXl8AtSzjHg=
github.com/erdrix/nigoapi v0.0.0-20211026105001-8b40a035361c/go.mod h1:owY+8fs8YXnST3ENM+ulVllYjTbzGaqKA+Y7HHJ0lZA=
github.com/erdrix/nigoapi v0.0.0-20211026110358-9bf3bfa29e46 h1:KshP0euoy8R3aVWgjJg0Zuk0TsO4Lbt/k/FvfVQneTo=
github.com/erdrix/nigoapi v0.0.0-20211026110358-9bf3bfa29e46/go.mod h1:owY+8fs8YXnST3ENM+ulVllYjTbzGaqKA+Y7HHJ0lZA=
github.com/erdrix/nigoapi v0.0.0-20211026131235-b258e0b217af h1:0t7jHTzu/UDzZqpgQKiCdQJ1JADPamrl2HMlWCuxRMQ=
github.com/erdrix/nigoapi v0.0.0-20211026131235-b258e0b217af/go.mod h1:owY+8fs8YXnST3ENM+ulVllYjTbzGaqKA+Y7HHJ0lZA=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible h1:kLcOMZeuLAJvL2BPWLMIj5oaZQobrkAqrL+WFZwQses=
Expand Down
4 changes: 2 additions & 2 deletions helm/nifikop/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ name: nifikop
home: https://github.com/Orange-OpenSource/nifikop
sources:
- https://github.com/Orange-OpenSource/nifikop
version: 0.7.0
appVersion: 0.7.0-release
version: 0.7.1
appVersion: 0.7.1-release
icon:
maintainers:
- name: erdrix
Expand Down
2 changes: 1 addition & 1 deletion helm/nifikop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The following tables lists the configurable parameters of the NiFi Operator Helm
| Parameter | Description | Default |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
| `image.repository` | Image | `orangeopensource/nifikop` |
| `image.tag` | Image tag | `v0.7.0-release` |
| `image.tag` | Image tag | `v0.7.1-release` |
| `image.pullPolicy` | Image pull policy | `Always` |
| `image.imagePullSecrets.enabled` | Enable tue use of secret for docker image | `false` |
| `image.imagePullSecrets.name` | Name of the secret to connect to docker registry | - |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
properties:
clusterRef:
description: contains the reference to the NifiCluster with the one
the dataflow is linked.
the parameter context is linked.
properties:
name:
type: string
Expand Down
2 changes: 1 addition & 1 deletion helm/nifikop/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##
image:
repository: orangeopensource/nifikop
tag: v0.7.0-release
tag: v0.7.1-release
pullPolicy: Always
imagePullSecrets:
enabled: false
Expand Down
13 changes: 7 additions & 6 deletions pkg/clientwrappers/parametercontext/parametercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ func parameterContextIsSync(
for _, param := range entity.Component.Parameters {
if expected.Parameter.Name == param.Parameter.Name {
notFound = false

if (!param.Parameter.Sensitive && *expected.Parameter.Value != *param.Parameter.Value) ||
if (!param.Parameter.Sensitive && ((expected.Parameter.Value == nil && param.Parameter.Value == nil) ||
((expected.Parameter.Value != nil && param.Parameter.Value != nil) &&
*expected.Parameter.Value != *param.Parameter.Value))) ||
expected.Parameter.Description != param.Parameter.Description {

return false
Expand Down Expand Up @@ -193,8 +194,9 @@ func updateRequestPrepare(
for _, param := range tmp {
if expected.Parameter.Name == param.Parameter.Name {
notFound = false

if (!param.Parameter.Sensitive && *expected.Parameter.Value != *param.Parameter.Value) ||
if (!param.Parameter.Sensitive && ((expected.Parameter.Value == nil && param.Parameter.Value == nil) ||
((expected.Parameter.Value != nil && param.Parameter.Value != nil) &&
*expected.Parameter.Value != *param.Parameter.Value))) ||
expected.Parameter.Description != param.Parameter.Description {
notFound = false
parameters = append(parameters, expected)
Expand Down Expand Up @@ -252,13 +254,12 @@ func updateParameterContextEntity(parameterContext *v1alpha1.NifiParameterContex
}

for _, parameter := range parameterContext.Spec.Parameters {
value := parameter.Value
parameters = append(parameters, nigoapi.ParameterEntity{
Parameter: &nigoapi.ParameterDto{
Name: parameter.Name,
Description: parameter.Description,
Sensitive: false,
Value: &value,
Value: parameter.Value,
},
})
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/clientwrappers/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func userContainsAccessPolicy(user *v1alpha1.NifiUser, entity nigoapi.AccessPoli
return false
}

func userEntityContainsAccessPolicy(entity *nigoapi.UserEntity, accessPolicy v1alpha1.AccessPolicy, rootPGId string) bool {
func userEntityContainsAccessPolicy(entity *nigoapi.UserEntity, accessPolicy v1alpha1.AccessPolicy, rootPGId string) bool {
for _, entity := range entity.Component.AccessPolicies {
if entity.Component.Action == string(accessPolicy.Action) &&
entity.Component.Resource == accessPolicy.GetResource(rootPGId) {
Expand All @@ -238,4 +238,3 @@ func userGroupEntityContainsAccessPolicyEntity(entity *nigoapi.UserGroupEntity,
}
return false
}

3 changes: 1 addition & 2 deletions pkg/clientwrappers/usergroup/usergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func updateUserGroupEntity(userGroup *v1alpha1.NifiUserGroup, users []*v1alpha1.
}
}


func userGroupContainsAccessPolicy(userGroup *v1alpha1.NifiUserGroup, entity nigoapi.AccessPolicyEntity, rootPGId string) bool {
for _, accessPolicy := range userGroup.Spec.AccessPolicies {
if entity.Component.Action == string(accessPolicy.Action) &&
Expand All @@ -217,4 +216,4 @@ func UserGroupEntityContainsAccessPolicy(entity *nigoapi.UserGroupEntity, access
}
}
return false
}
}
4 changes: 2 additions & 2 deletions site/docs/2_setup/1_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ Now deploy the helm chart :
helm install nifikop \
orange-incubator/nifikop \
--namespace=nifi \
--version 0.7.0 \
--set image.tag=v0.7.0-release \
--version 0.7.1 \
--set image.tag=v0.7.1release \
--set resources.requests.memory=256Mi \
--set resources.requests.cpu=250m \
--set resources.limits.memory=256Mi \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following tables lists the configurable parameters of the NiFi Operator Helm
| Parameter | Description | Default |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
| `image.repository` | Image | `orangeopensource/nifikop` |
| `image.tag` | Image tag | `v0.7.0-release` |
| `image.tag` | Image tag | `v0.7.1-release` |
| `image.pullPolicy` | Image pull policy | `Always` |
| `image.imagePullSecrets.enabled` | Enable tue use of secret for docker image | `false` |
| `image.imagePullSecrets.name` | Name of the secret to connect to docker registry | - |
Expand Down
Loading

0 comments on commit 4502cc0

Please sign in to comment.