From daca0025d54d581bb874780ee50be4115c03d6f1 Mon Sep 17 00:00:00 2001 From: Quique Llorente Date: Wed, 3 Mar 2021 15:32:05 +0100 Subject: [PATCH] Adapt code to new operator-sdk and kaw versions After bumping operator-sdk to 1.4.2 the Reconcile function expects a context.Context and the Meta at events is included in the client.Object passed to it. Signed-off-by: Quique Llorente --- controllers/nmstate_controller.go | 2 +- controllers/nmstate_controller_test.go | 8 +-- controllers/node_controller.go | 4 +- controllers/node_controller_test.go | 12 ++-- ...denetworkconfigurationpolicy_controller.go | 14 ++--- ...workconfigurationpolicy_controller_test.go | 27 ++++----- controllers/nodenetworkstate_controller.go | 10 ++-- deploy/crds/nmstate.io_nmstates.yaml | 16 ++++-- ...io_nodenetworkconfigurationenactments.yaml | 43 +++++++++----- ...e.io_nodenetworkconfigurationpolicies.yaml | 56 +++++++++++++------ deploy/crds/nmstate.io_nodenetworkstates.yaml | 30 +++++++--- deploy/handler/operator.yaml | 10 +++- deploy/handler/role.yaml | 8 +++ pkg/enactmentstatus/conditions/conditions.go | 2 +- pkg/enactmentstatus/status.go | 2 +- pkg/helper/client.go | 2 +- pkg/nmstatectl/nmstatectl.go | 2 +- pkg/nmstatectl/unavailable_link_workaround.go | 2 +- pkg/policyconditions/conditions.go | 2 +- pkg/probe/probes.go | 2 +- pkg/selectors/selectors.go | 2 +- .../conditions.go | 2 +- .../nodenetworkconfigurationpolicy/handler.go | 2 +- 23 files changed, 168 insertions(+), 92 deletions(-) diff --git a/controllers/nmstate_controller.go b/controllers/nmstate_controller.go index 7464a21e39..7856279fbf 100644 --- a/controllers/nmstate_controller.go +++ b/controllers/nmstate_controller.go @@ -59,7 +59,7 @@ type NMStateReconciler struct { // +kubebuilder:rbac:groups=apps,resources=deployments;daemonsets;replicasets;statefulsets,verbs="*" // +kubebuilder:rbac:groups="",resources=serviceaccounts;configmaps;namespaces;statefulsets,verbs="*" -func (r *NMStateReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { +func (r *NMStateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { _ = context.Background() _ = r.Log.WithValues("nmstate", req.NamespacedName) diff --git a/controllers/nmstate_controller_test.go b/controllers/nmstate_controller_test.go index b08792cf78..c31ecbeefc 100644 --- a/controllers/nmstate_controller_test.go +++ b/controllers/nmstate_controller_test.go @@ -79,7 +79,7 @@ var _ = Describe("NMState controller reconcile", func() { request.Name = "not-present-node" }) It("should return empty result", func() { - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) Expect(result).To(Equal(ctrl.Result{})) }) @@ -92,7 +92,7 @@ var _ = Describe("NMState controller reconcile", func() { request.Name = existingNMStateName }) It("should return a Result", func() { - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) Expect(result).To(Equal(ctrl.Result{})) }) @@ -111,7 +111,7 @@ var _ = Describe("NMState controller reconcile", func() { } }) It("should return error", func() { - _, err := reconciler.Reconcile(request) + _, err := reconciler.Reconcile(context.Background(), request) Expect(err).To(HaveOccurred()) }) }) @@ -131,7 +131,7 @@ var _ = Describe("NMState controller reconcile", func() { cl = fake.NewFakeClientWithScheme(s, objs...) reconciler.Client = cl request.Name = existingNMStateName - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) Expect(result).To(Equal(ctrl.Result{})) }) diff --git a/controllers/node_controller.go b/controllers/node_controller.go index 806fef175a..3d5a1d6cba 100644 --- a/controllers/node_controller.go +++ b/controllers/node_controller.go @@ -57,7 +57,7 @@ type NodeReconciler struct { // Note: // The Controller will requeue the Request to be processed again if the returned error is non-nil or // Result.Requeue is true, otherwise upon completion it will remove the work from the queue. -func (r *NodeReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { +func (r *NodeReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { currentStateRaw, err := r.nmstatectlShow() if err != nil { // We cannot call nmstatectl show let's reconcile again @@ -110,7 +110,7 @@ func (r *NodeReconciler) SetupWithManager(mgr ctrl.Manager) error { // but we only want to watch create/delete for current node. onCreationForThisNode := predicate.Funcs{ CreateFunc: func(createEvent event.CreateEvent) bool { - return nmstate.EventIsForThisNode(createEvent.Meta) + return nmstate.EventIsForThisNode(createEvent.Object) }, DeleteFunc: func(event.DeleteEvent) bool { return false diff --git a/controllers/node_controller_test.go b/controllers/node_controller_test.go index 9a59d2878d..4b15ab0f4e 100644 --- a/controllers/node_controller_test.go +++ b/controllers/node_controller_test.go @@ -94,7 +94,7 @@ routes: } }) It("should return the error from nmstatectl", func() { - _, err := reconciler.Reconcile(request) + _, err := reconciler.Reconcile(context.Background(), request) Expect(err).To(MatchError("forced failure at unit test")) }) }) @@ -110,7 +110,7 @@ routes: } }) It("should not call nmstateUpdater and return a Result with RequeueAfter set", func() { - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) expectRequeueAfterIsSetWithNetworkStateRefresh(result) }) @@ -123,7 +123,7 @@ routes: request.Name = "not-present-node" }) It("should returns empty result", func() { - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) Expect(result).To(Equal(reconcile.Result{})) }) @@ -162,7 +162,7 @@ routes: }) It("should call nmstateUpdater and return a Result with RequeueAfter set (trigger re-reconciliation)", func() { - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) expectRequeueAfterIsSetWithNetworkStateRefresh(result) obtainedNNS := nmstatev1beta1.NodeNetworkState{} @@ -180,7 +180,7 @@ routes: Expect(err).ToNot(HaveOccurred()) }) It("should create a new nodenetworkstate with node as owner reference, making sure the nodenetworkstate will be removed when the node is deleted", func() { - _, err := reconciler.Reconcile(request) + _, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) obtainedNNS := nmstatev1beta1.NodeNetworkState{} @@ -194,7 +194,7 @@ routes: )) }) It("should return a Result with RequeueAfter set (trigger re-reconciliation)", func() { - result, err := reconciler.Reconcile(request) + result, err := reconciler.Reconcile(context.Background(), request) Expect(err).ToNot(HaveOccurred()) expectRequeueAfterIsSetWithNetworkStateRefresh(result) }) diff --git a/controllers/nodenetworkconfigurationpolicy_controller.go b/controllers/nodenetworkconfigurationpolicy_controller.go index cbac1b9e7c..a053a7d050 100644 --- a/controllers/nodenetworkconfigurationpolicy_controller.go +++ b/controllers/nodenetworkconfigurationpolicy_controller.go @@ -65,7 +65,7 @@ var ( }, UpdateFunc: func(updateEvent event.UpdateEvent) bool { // [1] https://blog.openshift.com/kubernetes-operators-best-practices/ - generationIsDifferent := updateEvent.MetaNew.GetGeneration() != updateEvent.MetaOld.GetGeneration() + generationIsDifferent := updateEvent.ObjectNew.GetGeneration() != updateEvent.ObjectOld.GetGeneration() return generationIsDifferent }, } @@ -78,8 +78,8 @@ var ( return false }, UpdateFunc: func(updateEvent event.UpdateEvent) bool { - labelsChanged := !reflect.DeepEqual(updateEvent.MetaOld.GetLabels(), updateEvent.MetaNew.GetLabels()) - return labelsChanged && nmstate.EventIsForThisNode(updateEvent.MetaNew) + labelsChanged := !reflect.DeepEqual(updateEvent.ObjectOld.GetLabels(), updateEvent.ObjectNew.GetLabels()) + return labelsChanged && nmstate.EventIsForThisNode(updateEvent.ObjectNew) }, GenericFunc: func(event.GenericEvent) bool { return false @@ -199,7 +199,7 @@ func (r *NodeNetworkConfigurationPolicyReconciler) releaseNodeRunningUpdate(poli // Note: // The Controller will requeue the Request to be processed again if the returned error is non-nil or // Result.Requeue is true, otherwise upon completion it will remove the work from the queue. -func (r *NodeNetworkConfigurationPolicyReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { +func (r *NodeNetworkConfigurationPolicyReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { _ = context.Background() log := r.Log.WithValues("nodenetworkconfigurationpolicy", request.NamespacedName) @@ -288,8 +288,8 @@ func (r *NodeNetworkConfigurationPolicyReconciler) Reconcile(request ctrl.Reques func (r *NodeNetworkConfigurationPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { - allPolicies := handler.ToRequestsFunc( - func(handler.MapObject) []reconcile.Request { + allPolicies := handler.MapFunc( + func(client.Object) []reconcile.Request { log := r.Log.WithName("allPolicies") allPoliciesAsRequest := []reconcile.Request{} policyList := nmstatev1beta1.NodeNetworkConfigurationPolicyList{} @@ -320,7 +320,7 @@ func (r *NodeNetworkConfigurationPolicyReconciler) SetupWithManager(mgr ctrl.Man // is not needed since all NNCPs are going to be Reconcile at node startup. err = ctrl.NewControllerManagedBy(mgr). For(&corev1.Node{}). - Watches(&source.Kind{Type: &corev1.Node{}}, &handler.EnqueueRequestsFromMapFunc{ToRequests: allPolicies}, builder.WithPredicates(onLabelsUpdatedForThisNode)). + Watches(&source.Kind{Type: &corev1.Node{}}, handler.EnqueueRequestsFromMapFunc(allPolicies), builder.WithPredicates(onLabelsUpdatedForThisNode)). Complete(r) if err != nil { return errors.Wrap(err, "failed to add controller to NNCP Reconciler listening Node events") diff --git a/controllers/nodenetworkconfigurationpolicy_controller_test.go b/controllers/nodenetworkconfigurationpolicy_controller_test.go index b3bb7c1575..29055ea058 100644 --- a/controllers/nodenetworkconfigurationpolicy_controller_test.go +++ b/controllers/nodenetworkconfigurationpolicy_controller_test.go @@ -20,34 +20,31 @@ var _ = Describe("NodeNetworkConfigurationPolicy controller predicates", func() } DescribeTable("testing predicates", func(c predicateCase) { - oldNodeNetworkConfigurationPolicyMeta := metav1.ObjectMeta{ - Generation: c.GenerationOld, + oldNNCP := nmstatev1beta1.NodeNetworkConfigurationPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Generation: c.GenerationOld, + }, } - - newNodeNetworkConfigurationPolicyMeta := metav1.ObjectMeta{ - Generation: c.GenerationNew, + newNNCP := nmstatev1beta1.NodeNetworkConfigurationPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Generation: c.GenerationNew, + }, } - nodeNetworkConfigurationPolicy := nmstatev1beta1.NodeNetworkConfigurationPolicy{} - predicate := onCreateOrUpdateWithDifferentGeneration Expect(predicate. CreateFunc(event.CreateEvent{ - Meta: &newNodeNetworkConfigurationPolicyMeta, - Object: &nodeNetworkConfigurationPolicy, + Object: &newNNCP, })).To(Equal(c.ReconcileCreate)) Expect(predicate. UpdateFunc(event.UpdateEvent{ - MetaOld: &oldNodeNetworkConfigurationPolicyMeta, - ObjectOld: &nodeNetworkConfigurationPolicy, - MetaNew: &newNodeNetworkConfigurationPolicyMeta, - ObjectNew: &nodeNetworkConfigurationPolicy, + ObjectOld: &oldNNCP, + ObjectNew: &newNNCP, })).To(Equal(c.ReconcileUpdate)) Expect(predicate. DeleteFunc(event.DeleteEvent{ - Meta: &newNodeNetworkConfigurationPolicyMeta, - Object: &nodeNetworkConfigurationPolicy, + Object: &newNNCP, })).To(BeFalse()) }, Entry("generation remains the same", diff --git a/controllers/nodenetworkstate_controller.go b/controllers/nodenetworkstate_controller.go index f7ce482c80..a170c26231 100644 --- a/controllers/nodenetworkstate_controller.go +++ b/controllers/nodenetworkstate_controller.go @@ -50,7 +50,7 @@ type NodeNetworkStateReconciler struct { // Note: // The Controller will requeue the Request to be processed again if the returned error is non-nil or // Result.Requeue is true, otherwise upon completion it will remove the work from the queue. -func (r *NodeNetworkStateReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { +func (r *NodeNetworkStateReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { // Fetch the Node instance node := &corev1.Node{} err := r.Client.Get(context.TODO(), request.NamespacedName, node) @@ -94,10 +94,10 @@ func (r *NodeNetworkStateReconciler) SetupWithManager(mgr ctrl.Manager) error { return false }, DeleteFunc: func(deleteEvent event.DeleteEvent) bool { - return nmstate.EventIsForThisNode(deleteEvent.Meta) + return nmstate.EventIsForThisNode(deleteEvent.Object) }, UpdateFunc: func(updateEvent event.UpdateEvent) bool { - return nmstate.EventIsForThisNode(updateEvent.MetaNew) && + return nmstate.EventIsForThisNode(updateEvent.ObjectNew) && shouldForceRefresh(updateEvent) }, GenericFunc: func(event.GenericEvent) bool { @@ -112,11 +112,11 @@ func (r *NodeNetworkStateReconciler) SetupWithManager(mgr ctrl.Manager) error { } func shouldForceRefresh(updateEvent event.UpdateEvent) bool { - newForceRefresh, hasForceRefreshNow := updateEvent.MetaNew.GetLabels()[forceRefreshLabel] + newForceRefresh, hasForceRefreshNow := updateEvent.ObjectNew.GetLabels()[forceRefreshLabel] if !hasForceRefreshNow { return false } - oldForceRefresh, hasForceRefreshLabelPreviously := updateEvent.MetaOld.GetLabels()[forceRefreshLabel] + oldForceRefresh, hasForceRefreshLabelPreviously := updateEvent.ObjectOld.GetLabels()[forceRefreshLabel] if !hasForceRefreshLabelPreviously { return true } diff --git a/deploy/crds/nmstate.io_nmstates.yaml b/deploy/crds/nmstate.io_nmstates.yaml index 89d3e751ea..d6455fd811 100644 --- a/deploy/crds/nmstate.io_nmstates.yaml +++ b/deploy/crds/nmstate.io_nmstates.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: nmstates.nmstate.io spec: @@ -22,10 +22,14 @@ spec: description: NMState is the Schema for the nmstates API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object @@ -35,7 +39,11 @@ spec: nodeSelector: additionalProperties: type: string - description: NodeSelector is an optional selector that will be added to handler DaemonSet manifest for both workers and masters (https://github.com/nmstate/kubernetes-nmstate/blob/master/deploy/handler/operator.yaml). If NodeSelector is specified, the handler will run only on nodes that have each of the indicated key-value pairs as labels applied to the node. + description: NodeSelector is an optional selector that will be added + to handler DaemonSet manifest for both workers and masters (https://github.com/nmstate/kubernetes-nmstate/blob/master/deploy/handler/operator.yaml). + If NodeSelector is specified, the handler will run only on nodes + that have each of the indicated key-value pairs as labels applied + to the node. type: object type: object status: diff --git a/deploy/crds/nmstate.io_nodenetworkconfigurationenactments.yaml b/deploy/crds/nmstate.io_nodenetworkconfigurationenactments.yaml index 2c7b9f1668..a278c6a161 100644 --- a/deploy/crds/nmstate.io_nodenetworkconfigurationenactments.yaml +++ b/deploy/crds/nmstate.io_nodenetworkconfigurationenactments.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: nodenetworkconfigurationenactments.nmstate.io spec: @@ -26,18 +26,24 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: NodeNetworkConfigurationEnactment is the Schema for the nodenetworkconfigurationenactments API + description: NodeNetworkConfigurationEnactment is the Schema for the nodenetworkconfigurationenactments + API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object status: - description: NodeNetworkConfigurationEnactmentStatus defines the observed state of NodeNetworkConfigurationEnactment + description: NodeNetworkConfigurationEnactmentStatus defines the observed + state of NodeNetworkConfigurationEnactment properties: conditions: items: @@ -62,11 +68,13 @@ spec: type: object type: array desiredState: - description: The desired state rendered for the enactment's node using the policy desiredState as template + description: The desired state rendered for the enactment's node using + the policy desiredState as template type: object x-kubernetes-preserve-unknown-fields: true policyGeneration: - description: The generation from policy needed to check if an enactment condition status belongs to the same policy version + description: The generation from policy needed to check if an enactment + condition status belongs to the same policy version format: int64 type: integer type: object @@ -83,18 +91,24 @@ spec: name: v1beta1 schema: openAPIV3Schema: - description: NodeNetworkConfigurationEnactment is the Schema for the nodenetworkconfigurationenactments API + description: NodeNetworkConfigurationEnactment is the Schema for the nodenetworkconfigurationenactments + API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object status: - description: NodeNetworkConfigurationEnactmentStatus defines the observed state of NodeNetworkConfigurationEnactment + description: NodeNetworkConfigurationEnactmentStatus defines the observed + state of NodeNetworkConfigurationEnactment properties: conditions: items: @@ -119,15 +133,18 @@ spec: type: object type: array desiredState: - description: The desired state rendered for the enactment's node using the policy desiredState as template + description: The desired state rendered for the enactment's node using + the policy desiredState as template type: object x-kubernetes-preserve-unknown-fields: true policyGeneration: - description: The generation from policy needed to check if an enactment condition status belongs to the same policy version + description: The generation from policy needed to check if an enactment + condition status belongs to the same policy version format: int64 type: integer type: object type: object + x-kubernetes-preserve-unknown-fields: true served: true storage: true subresources: diff --git a/deploy/crds/nmstate.io_nodenetworkconfigurationpolicies.yaml b/deploy/crds/nmstate.io_nodenetworkconfigurationpolicies.yaml index 90451122e2..74edfd25b9 100644 --- a/deploy/crds/nmstate.io_nodenetworkconfigurationpolicies.yaml +++ b/deploy/crds/nmstate.io_nodenetworkconfigurationpolicies.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: nodenetworkconfigurationpolicies.nmstate.io spec: @@ -26,18 +26,24 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: NodeNetworkConfigurationPolicy is the Schema for the nodenetworkconfigurationpolicies API + description: NodeNetworkConfigurationPolicy is the Schema for the nodenetworkconfigurationpolicies + API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object spec: - description: NodeNetworkConfigurationPolicySpec defines the desired state of NodeNetworkConfigurationPolicy + description: NodeNetworkConfigurationPolicySpec defines the desired state + of NodeNetworkConfigurationPolicy properties: desiredState: description: The desired configuration of the policy @@ -46,14 +52,18 @@ spec: nodeSelector: additionalProperties: type: string - description: 'NodeSelector is a selector which must be true for the policy to be applied to the node. Selector which must match a node''s labels for the policy to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/' + description: 'NodeSelector is a selector which must be true for the + policy to be applied to the node. Selector which must match a node''s + labels for the policy to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/' type: object parallel: - description: When set to true, changes are applied to all nodes in parallel + description: When set to true, changes are applied to all nodes in + parallel type: boolean type: object status: - description: NodeNetworkConfigurationPolicyStatus defines the observed state of NodeNetworkConfigurationPolicy + description: NodeNetworkConfigurationPolicyStatus defines the observed + state of NodeNetworkConfigurationPolicy properties: conditions: items: @@ -78,7 +88,8 @@ spec: type: object type: array nodeRunningUpdate: - description: NodeRunningUpdate field is used for serializing cluster nodes configuration when Parallel flag is false + description: NodeRunningUpdate field is used for serializing cluster + nodes configuration when Parallel flag is false type: string type: object type: object @@ -94,18 +105,24 @@ spec: name: v1beta1 schema: openAPIV3Schema: - description: NodeNetworkConfigurationPolicy is the Schema for the nodenetworkconfigurationpolicies API + description: NodeNetworkConfigurationPolicy is the Schema for the nodenetworkconfigurationpolicies + API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object spec: - description: NodeNetworkConfigurationPolicySpec defines the desired state of NodeNetworkConfigurationPolicy + description: NodeNetworkConfigurationPolicySpec defines the desired state + of NodeNetworkConfigurationPolicy properties: desiredState: description: The desired configuration of the policy @@ -114,14 +131,18 @@ spec: nodeSelector: additionalProperties: type: string - description: 'NodeSelector is a selector which must be true for the policy to be applied to the node. Selector which must match a node''s labels for the policy to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/' + description: 'NodeSelector is a selector which must be true for the + policy to be applied to the node. Selector which must match a node''s + labels for the policy to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/' type: object parallel: - description: When set to true, changes are applied to all nodes in parallel + description: When set to true, changes are applied to all nodes in + parallel type: boolean type: object status: - description: NodeNetworkConfigurationPolicyStatus defines the observed state of NodeNetworkConfigurationPolicy + description: NodeNetworkConfigurationPolicyStatus defines the observed + state of NodeNetworkConfigurationPolicy properties: conditions: items: @@ -146,7 +167,8 @@ spec: type: object type: array nodeRunningUpdate: - description: NodeRunningUpdate field is used for serializing cluster nodes configuration when Parallel flag is false + description: NodeRunningUpdate field is used for serializing cluster + nodes configuration when Parallel flag is false type: string type: object type: object diff --git a/deploy/crds/nmstate.io_nodenetworkstates.yaml b/deploy/crds/nmstate.io_nodenetworkstates.yaml index 75767f07b9..e456caa49b 100644 --- a/deploy/crds/nmstate.io_nodenetworkstates.yaml +++ b/deploy/crds/nmstate.io_nodenetworkstates.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: nodenetworkstates.nmstate.io spec: @@ -24,15 +24,20 @@ spec: description: NodeNetworkState is the Schema for the nodenetworkstates API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object status: - description: NodeNetworkStateStatus is the status of the NodeNetworkState of a specific node + description: NodeNetworkStateStatus is the status of the NodeNetworkState + of a specific node properties: conditions: items: @@ -57,6 +62,9 @@ spec: type: object type: array currentState: + description: "State contains the namestatectl yaml [1] as string instead + of golang struct so we don't need to be in sync with the schema. + \n [1] https://github.com/nmstate/nmstate/blob/base/libnmstate/schemas/operational-state.yaml" type: object x-kubernetes-preserve-unknown-fields: true lastSuccessfulUpdateTime: @@ -74,15 +82,20 @@ spec: description: NodeNetworkState is the Schema for the nodenetworkstates API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object status: - description: NodeNetworkStateStatus is the status of the NodeNetworkState of a specific node + description: NodeNetworkStateStatus is the status of the NodeNetworkState + of a specific node properties: conditions: items: @@ -107,6 +120,9 @@ spec: type: object type: array currentState: + description: "State contains the namestatectl yaml [1] as string instead + of golang struct so we don't need to be in sync with the schema. + \n [1] https://github.com/nmstate/nmstate/blob/base/libnmstate/schemas/operational-state.yaml" type: object x-kubernetes-preserve-unknown-fields: true lastSuccessfulUpdateTime: diff --git a/deploy/handler/operator.yaml b/deploy/handler/operator.yaml index c8942fc6bd..178ea0c2d5 100644 --- a/deploy/handler/operator.yaml +++ b/deploy/handler/operator.yaml @@ -191,7 +191,7 @@ spec: selector: name: {{template "handlerPrefix" .}}nmstate-webhook --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: {{template "handlerPrefix" .}}nmstate @@ -199,6 +199,8 @@ metadata: app: kubernetes-nmstate webhooks: - name: nodenetworkconfigurationpolicies-mutate.nmstate.io + admissionReviewVersions: ["v1", "v1beta1"] + sideEffects: None clientConfig: service: name: {{template "handlerPrefix" .}}nmstate-webhook @@ -210,6 +212,8 @@ webhooks: apiVersions: ["v1alpha1","v1beta1"] resources: ["nodenetworkconfigurationpolicies"] - name: nodenetworkconfigurationpolicies-status-mutate.nmstate.io + admissionReviewVersions: ["v1", "v1beta1"] + sideEffects: None clientConfig: service: name: {{template "handlerPrefix" .}}nmstate-webhook @@ -221,6 +225,8 @@ webhooks: apiVersions: ["v1alpha1","v1beta1"] resources: ["nodenetworkconfigurationpolicies/status"] - name: nodenetworkconfigurationpolicies-timestamp-mutate.nmstate.io + admissionReviewVersions: ["v1", "v1beta1"] + sideEffects: None clientConfig: service: name: {{template "handlerPrefix" .}}nmstate-webhook @@ -232,6 +238,8 @@ webhooks: apiVersions: ["v1alpha1","v1beta1"] resources: ["nodenetworkconfigurationpolicies", "nodenetworkconfigurationpolicies/status"] - name: nodenetworkconfigurationpolicies-progress-validate.nmstate.io + admissionReviewVersions: ["v1", "v1beta1"] + sideEffects: None clientConfig: service: name: {{template "handlerPrefix" .}}nmstate-webhook diff --git a/deploy/handler/role.yaml b/deploy/handler/role.yaml index 84f52c6ac9..0d1af3bd28 100644 --- a/deploy/handler/role.yaml +++ b/deploy/handler/role.yaml @@ -65,6 +65,14 @@ rules: - deployments/finalizers verbs: - update +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - create + - update --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole diff --git a/pkg/enactmentstatus/conditions/conditions.go b/pkg/enactmentstatus/conditions/conditions.go index 302f215990..dfbfc4b285 100644 --- a/pkg/enactmentstatus/conditions/conditions.go +++ b/pkg/enactmentstatus/conditions/conditions.go @@ -9,7 +9,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" nmstate "github.com/nmstate/kubernetes-nmstate/api/shared" "github.com/nmstate/kubernetes-nmstate/pkg/enactmentstatus" diff --git a/pkg/enactmentstatus/status.go b/pkg/enactmentstatus/status.go index f47c4095c4..b7aae9c90a 100644 --- a/pkg/enactmentstatus/status.go +++ b/pkg/enactmentstatus/status.go @@ -7,7 +7,7 @@ import ( "time" "github.com/pkg/errors" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" diff --git a/pkg/helper/client.go b/pkg/helper/client.go index 3fd877a7e7..95991b8df2 100644 --- a/pkg/helper/client.go +++ b/pkg/helper/client.go @@ -13,7 +13,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" "github.com/nmstate/kubernetes-nmstate/api/shared" nmstatev1beta1 "github.com/nmstate/kubernetes-nmstate/api/v1beta1" diff --git a/pkg/nmstatectl/nmstatectl.go b/pkg/nmstatectl/nmstatectl.go index 70ed854377..a4d42d92e0 100644 --- a/pkg/nmstatectl/nmstatectl.go +++ b/pkg/nmstatectl/nmstatectl.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" nmstate "github.com/nmstate/kubernetes-nmstate/api/shared" ) diff --git a/pkg/nmstatectl/unavailable_link_workaround.go b/pkg/nmstatectl/unavailable_link_workaround.go index e52f319121..eab853386a 100644 --- a/pkg/nmstatectl/unavailable_link_workaround.go +++ b/pkg/nmstatectl/unavailable_link_workaround.go @@ -8,7 +8,7 @@ import ( networkmanager "github.com/phoracek/networkmanager-go/src" "k8s.io/apimachinery/pkg/util/wait" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" ) var ( diff --git a/pkg/policyconditions/conditions.go b/pkg/policyconditions/conditions.go index 008c0ad867..b3d0909d6f 100644 --- a/pkg/policyconditions/conditions.go +++ b/pkg/policyconditions/conditions.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/retry" client "sigs.k8s.io/controller-runtime/pkg/client" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" nmstate "github.com/nmstate/kubernetes-nmstate/api/shared" nmstatev1beta1 "github.com/nmstate/kubernetes-nmstate/api/v1beta1" diff --git a/pkg/probe/probes.go b/pkg/probe/probes.go index 0085ccd9be..74d5128308 100644 --- a/pkg/probe/probes.go +++ b/pkg/probe/probes.go @@ -15,7 +15,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" yaml "sigs.k8s.io/yaml" "github.com/tidwall/gjson" diff --git a/pkg/selectors/selectors.go b/pkg/selectors/selectors.go index 60ab9b69f9..5aa62cd8d2 100644 --- a/pkg/selectors/selectors.go +++ b/pkg/selectors/selectors.go @@ -4,7 +4,7 @@ import ( "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" nmstatev1beta1 "github.com/nmstate/kubernetes-nmstate/api/v1beta1" ) diff --git a/pkg/webhook/nodenetworkconfigurationpolicy/conditions.go b/pkg/webhook/nodenetworkconfigurationpolicy/conditions.go index d061323fad..af9147d10c 100644 --- a/pkg/webhook/nodenetworkconfigurationpolicy/conditions.go +++ b/pkg/webhook/nodenetworkconfigurationpolicy/conditions.go @@ -2,7 +2,7 @@ package nodenetworkconfigurationpolicy import ( corev1 "k8s.io/api/core/v1" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" diff --git a/pkg/webhook/nodenetworkconfigurationpolicy/handler.go b/pkg/webhook/nodenetworkconfigurationpolicy/handler.go index 5eb9fbcd44..ee9205c328 100644 --- a/pkg/webhook/nodenetworkconfigurationpolicy/handler.go +++ b/pkg/webhook/nodenetworkconfigurationpolicy/handler.go @@ -11,7 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission"