-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include capabilities in CSIAddonsNode status #635
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
csiaddonsv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/csiaddons/v1alpha1" | ||
"github.com/csi-addons/kubernetes-csi-addons/internal/connection" | ||
"github.com/csi-addons/kubernetes-csi-addons/internal/util" | ||
"github.com/csi-addons/spec/lib/go/identity" | ||
|
||
"github.com/go-logr/logr" | ||
corev1 "k8s.io/api/core/v1" | ||
|
@@ -142,6 +143,7 @@ func (r *CSIAddonsNodeReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
|
||
csiAddonsNode.Status.State = csiaddonsv1alpha1.CSIAddonsNodeStateConnected | ||
csiAddonsNode.Status.Message = "Successfully established connection with sidecar" | ||
csiAddonsNode.Status.Capabilities = parseCapabilities(newConn.Capabilities) | ||
err = r.Client.Status().Update(ctx, csiAddonsNode) | ||
if err != nil { | ||
logger.Error(err, "Failed to update status") | ||
|
@@ -271,3 +273,23 @@ func validateCSIAddonsNodeSpec(csiaddonsnode *csiaddonsv1alpha1.CSIAddonsNode) e | |
|
||
return nil | ||
} | ||
|
||
// parseCapabilities returns a list of capabilities in the format | ||
// capability.Type | ||
// e.g. A cap.String with value "service:{type:NODE_SERVICE}" | ||
// Will be parsed and returned as "service.NODE_SERVICE" | ||
func parseCapabilities(caps []*identity.Capability) []string { | ||
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. add unit test for this one? 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. Done. |
||
if len(caps) == 0 { | ||
return []string{} | ||
} | ||
|
||
capabilities := make([]string, len(caps)) | ||
|
||
for i, cap := range caps { | ||
capStr := strings.ReplaceAll(cap.String(), ":{type:", ".") | ||
capStr = strings.ReplaceAll(capStr, "}", "") | ||
capabilities[i] = capStr | ||
} | ||
|
||
return capabilities | ||
} |
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.
can you add a little note/example of how a
cap.String()
looks like, and what the desired output for it is?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.
Done