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.
-
Notifications
You must be signed in to change notification settings - Fork 17
Check for api client before using #123
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import ( | |
| // Node controller errors. | ||
| var ( | ||
| ErrCurrentClusterNotFound = errors.New("current cluster not found") | ||
| ErrNoAPIClient = errors.New("api client not available") | ||
| ) | ||
|
|
||
| // 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, | |
| return reconcileResult, err | ||
| } | ||
|
|
||
| // Set a storageos cluster client. | ||
| if r.stosClient != nil { | ||
| // Compare the cluster names, generations and UUIDs to check if it's | ||
| // the same cluster. Update the client if client cluster name, | ||
| // generation or UID are different from current cluster. | ||
| if r.stosClient.clusterName != cluster.GetName() || | ||
| r.stosClient.clusterGeneration != cluster.GetGeneration() || | ||
| r.stosClient.clusterUID != cluster.GetUID() { | ||
| r.setClientForCluster(cluster) | ||
| // Compare the cluster names, generations and UUIDs to check if it's | ||
| // the same cluster. Update the client if client cluster name, | ||
| // generation or UID are different from current cluster. | ||
| if r.stosClient == nil || | ||
| r.stosClient.clusterName != cluster.GetName() || | ||
| r.stosClient.clusterGeneration != cluster.GetGeneration() || | ||
| r.stosClient.clusterUID != cluster.GetUID() { | ||
|
|
||
| if err := r.setClientForCluster(cluster); err != nil { | ||
| log.Println("failed to configure api client:", err) | ||
| return reconcileResult, err | ||
| } | ||
| } else { | ||
| // No previous client. Create a new client. | ||
| r.setClientForCluster(cluster) | ||
| } | ||
|
|
||
| // Sync labels to StorageOS node object. | ||
|
|
@@ -130,6 +130,10 @@ func (r *ReconcileNode) syncLabels(name string, labels map[string]string) error | |
| return nil | ||
| } | ||
|
|
||
| if r.stosClient == nil { | ||
| return ErrNoAPIClient | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. We need to add more tests for the functions in each of the controllers. |
||
| // Get StorageOS node | ||
| node, err := r.stosClient.Node(name) | ||
| if err != nil { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much better 👍 return error and requeue the request.
I missed error checking 😅