From c684a5f9ac98506444f52e0cdbdd9dcd4fb71afd Mon Sep 17 00:00:00 2001 From: yaocw2020 Date: Tue, 30 Mar 2021 15:16:36 +0800 Subject: [PATCH] Initialize nodenetwork status --- .../crds/network.harvester.cattle.io_nodenetworks.yaml | 3 +-- manifests/rbac.yaml | 2 +- .../network.harvester.cattle.io/v1alpha1/nodenetwork.go | 1 - pkg/controller/agent/nodenetwork/controller.go | 9 ++++----- pkg/controller/common/nodenetwork.go | 5 +++++ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifests/crds/network.harvester.cattle.io_nodenetworks.yaml b/manifests/crds/network.harvester.cattle.io_nodenetworks.yaml index 0554f7b19..a53d7834e 100644 --- a/manifests/crds/network.harvester.cattle.io_nodenetworks.yaml +++ b/manifests/crds/network.harvester.cattle.io_nodenetworks.yaml @@ -166,8 +166,7 @@ spec: type: object served: true storage: true - subresources: - status: {} + subresources: {} status: acceptedNames: kind: "" diff --git a/manifests/rbac.yaml b/manifests/rbac.yaml index 24c387bae..913a43e38 100644 --- a/manifests/rbac.yaml +++ b/manifests/rbac.yaml @@ -14,7 +14,7 @@ metadata: name: harvester-network-controller rules: - apiGroups: [ "network.harvester.cattle.io" ] - resources: [ "clusternetworks", "nodenetworks", "nodenetworks/status" ] + resources: [ "clusternetworks", "nodenetworks" ] verbs: [ "get", "watch", "list", "update", "create", "delete" ] - apiGroups: [ "k8s.cni.cncf.io" ] resources: [ "network-attachment-definitions" ] diff --git a/pkg/apis/network.harvester.cattle.io/v1alpha1/nodenetwork.go b/pkg/apis/network.harvester.cattle.io/v1alpha1/nodenetwork.go index 3345920e1..25cae9e28 100644 --- a/pkg/apis/network.harvester.cattle.io/v1alpha1/nodenetwork.go +++ b/pkg/apis/network.harvester.cattle.io/v1alpha1/nodenetwork.go @@ -9,7 +9,6 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:resource:shortName=nn;nns,scope=Namespaced -// +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="DESCRIPTION",type=string,JSONPath=`.spec.description` // +kubebuilder:printcolumn:name="NODENAME",type=string,JSONPath=`.spec.nodeName` // +kubebuilder:printcolumn:name="TYPE",type=string,JSONPath=`.spec.type` diff --git a/pkg/controller/agent/nodenetwork/controller.go b/pkg/controller/agent/nodenetwork/controller.go index 482fb95f2..142ec99d0 100644 --- a/pkg/controller/agent/nodenetwork/controller.go +++ b/pkg/controller/agent/nodenetwork/controller.go @@ -126,7 +126,7 @@ func (h Handler) configVlanNetwork(nn *networkv1alpha1.NodeNetwork) error { func (h Handler) setupVlan(nn *networkv1alpha1.NodeNetwork) error { if nn.Spec.NIC == "" { return h.updateStatus(nn, network.Status{ - Condition: network.Condition{Normal: false, Message: "The physical NIC for VLAN network hasn't configured yet"}, + Condition: network.Condition{Normal: false, Message: "A physical NIC has not been specified yet"}, }) } @@ -138,13 +138,12 @@ func (h Handler) setupVlan(nn *networkv1alpha1.NodeNetwork) error { } if err = v.Setup(nn.Spec.NIC, vids); err != nil { - err = fmt.Errorf("set up vlan failed, error: %w, nic: %s", err, nn.Spec.NIC) if statusErr := h.updateStatus(nn, network.Status{ - Condition: network.Condition{Normal: false, Message: err.Error()}, + Condition: network.Condition{Normal: false, Message: "Setup VLAN network failed, please try another NIC"}, }); statusErr != nil { return statusErr } - return err + return fmt.Errorf("set up vlan failed, error: %w, nic: %s", err, nn.Spec.NIC) } status, err := v.Status(network.Condition{Normal: true, Message: ""}) @@ -241,7 +240,7 @@ func (h Handler) updateStatus(nn *networkv1alpha1.NodeNetwork, status network.St networkv1alpha1.NodeNetworkReady.SetStatusBool(nnCopy, status.Condition.Normal) networkv1alpha1.NodeNetworkReady.Message(nnCopy, status.Condition.Message) - if _, err := h.nodeNetworkCtr.UpdateStatus(nnCopy); err != nil { + if _, err := h.nodeNetworkCtr.Update(nnCopy); err != nil { return fmt.Errorf("update status of nodenetwork %s failed, error: %w", nn.Name, err) } diff --git a/pkg/controller/common/nodenetwork.go b/pkg/controller/common/nodenetwork.go index 9bee9cf14..848850876 100644 --- a/pkg/controller/common/nodenetwork.go +++ b/pkg/controller/common/nodenetwork.go @@ -17,6 +17,7 @@ const ( Namespace = "harvester-system" KeyNodeName = "NODENAME" KeyLabelNodeName = "network.harvester.cattle.io/nodename" + initStatusMsg = "Initializing network configuration" ) func NewNodeNetworkFromNode(node *corev1.Node, networkType networkv1alpha1.NetworkType, @@ -48,6 +49,10 @@ func NewNodeNetworkFromNode(node *corev1.Node, networkType networkv1alpha1.Netwo }, } + // initialize status + networkv1alpha1.NodeNetworkReady.SetStatusBool(nn, false) + networkv1alpha1.NodeNetworkReady.Message(nn, initStatusMsg) + switch networkType { case networkv1alpha1.NetworkTypeVLAN: defaultPhysicalNIC, ok := cn.Config[networkv1alpha1.KeyDefaultNIC]