Skip to content

Commit

Permalink
Initialize nodenetwork status
Browse files Browse the repository at this point in the history
  • Loading branch information
yaocw2020 authored and gitlawr committed Apr 1, 2021
1 parent f8b55a3 commit c684a5f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions manifests/crds/network.harvester.cattle.io_nodenetworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ spec:
type: object
served: true
storage: true
subresources:
status: {}
subresources: {}
status:
acceptedNames:
kind: ""
Expand Down
2 changes: 1 addition & 1 deletion manifests/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/agent/nodenetwork/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
})
}

Expand All @@ -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: ""})
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/common/nodenetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit c684a5f

Please sign in to comment.