Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit f3a7639

Browse files
authored
Check for api client before using (#123)
1 parent 0a7b7e4 commit f3a7639

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

pkg/controller/node/node_controller.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
// Node controller errors.
2828
var (
2929
ErrCurrentClusterNotFound = errors.New("current cluster not found")
30+
ErrNoAPIClient = errors.New("api client not available")
3031
)
3132

3233
// Add creates a new Node Controller and adds it to the Manager. The Manager will set fields on the Controller
@@ -99,19 +100,18 @@ func (r *ReconcileNode) Reconcile(request reconcile.Request) (reconcile.Result,
99100
return reconcileResult, err
100101
}
101102

102-
// Set a storageos cluster client.
103-
if r.stosClient != nil {
104-
// Compare the cluster names, generations and UUIDs to check if it's
105-
// the same cluster. Update the client if client cluster name,
106-
// generation or UID are different from current cluster.
107-
if r.stosClient.clusterName != cluster.GetName() ||
108-
r.stosClient.clusterGeneration != cluster.GetGeneration() ||
109-
r.stosClient.clusterUID != cluster.GetUID() {
110-
r.setClientForCluster(cluster)
103+
// Compare the cluster names, generations and UUIDs to check if it's
104+
// the same cluster. Update the client if client cluster name,
105+
// generation or UID are different from current cluster.
106+
if r.stosClient == nil ||
107+
r.stosClient.clusterName != cluster.GetName() ||
108+
r.stosClient.clusterGeneration != cluster.GetGeneration() ||
109+
r.stosClient.clusterUID != cluster.GetUID() {
110+
111+
if err := r.setClientForCluster(cluster); err != nil {
112+
log.Println("failed to configure api client:", err)
113+
return reconcileResult, err
111114
}
112-
} else {
113-
// No previous client. Create a new client.
114-
r.setClientForCluster(cluster)
115115
}
116116

117117
// Sync labels to StorageOS node object.
@@ -130,6 +130,10 @@ func (r *ReconcileNode) syncLabels(name string, labels map[string]string) error
130130
return nil
131131
}
132132

133+
if r.stosClient == nil {
134+
return ErrNoAPIClient
135+
}
136+
133137
// Get StorageOS node
134138
node, err := r.stosClient.Node(name)
135139
if err != nil {

0 commit comments

Comments
 (0)