-
Notifications
You must be signed in to change notification settings - Fork 61
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
Improve the cmd: get clusters #449
Conversation
cmoulliard
commented
Nov 14, 2024
•
edited
Loading
edited
- Improve the cmd: get clusters to show the cluster, nodes and their internal IP.
- Created a help function to access globally to the kube client.
- Add a new parameter to set the kubeconfig path
- Command currently shows:
- Add list clusters command #445
… internal IP. Created a help function to create globally a kube client. cnoe-io#445 Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
If several clusters/contexts/nodes have been created, then the command will output the following information:
|
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
I refactored the code to show the clusters using a Table
|
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
pkg/cmd/helpers/k8s.go
Outdated
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.
Once the static password PR merges, we could merge these into the util package. No action needed for this PR imo
pkg/cmd/get/clusters.go
Outdated
c, found := findClusterByName(config, "kind-"+cluster) | ||
if !found { | ||
//logger.Error(nil, fmt.Sprintf("Cluster not found: %s within kube config file\n", cluster)) | ||
return nil, err |
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.
Log and continue here instead? Even if client doesn't exist for some reason, we can find other valid clusters.
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.
Yes. This is better to continue and to log a message. See: 031e81b
//logger.Error(err, "failed to get the allocated resources.") | ||
return nil, err | ||
} | ||
aNode.Allocated = allocated |
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.
Are we doing anything with aNode
? Looks like it's discarded each iteration?
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.
Good question. Do we want part of the command "get clusters" to also show the allocated or available resources OR this is something that we will only show when we will display the detail of a cluster ?
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.
Hmm it would be nice to have but I'd say it's not critical since you can get that information with kubectl describe nodes
command.
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.
The big plus of our command is that we could show everything with one command (= developer like that) in one place vs running several kubectl commands ;-)
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.
I don't see aNode
value used for anything here still.
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.
Added a new column to list the nodes
NAME EXTERNAL-PORT KUBE-API TLS KUBE-PORT NODES
my-konflux 8443 https://127.0.0.1:57063 false 6443 my-konflux-control-plane
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.
See: 9fc54e2
Signed-off-by: cmoulliard <[email protected]>
…ubeconfig file BUT we log a message Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Can we merge it ? @nabuskey |
pkg/cmd/get/clusters.go
Outdated
|
||
detectOpt, err := util.DetectKindNodeProvider() | ||
if err != nil { | ||
//logger.Error(err, "failed to detect the provider.") |
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.
remove commented out logger message like this
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.
Removed the comments.
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.
See: 9fc54e2
pkg/cmd/root.go
Outdated
@@ -21,6 +21,7 @@ var rootCmd = &cobra.Command{ | |||
func init() { | |||
rootCmd.PersistentFlags().StringVarP(&helpers.LogLevel, "log-level", "l", "info", helpers.LogLevelMsg) | |||
rootCmd.PersistentFlags().BoolVar(&helpers.ColoredOutput, "color", false, helpers.ColoredOutputMsg) | |||
rootCmd.PersistentFlags().StringVarP(&helpers.KubeConfigPath, "kubeconfig", "", "", "kube config file Path.") |
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 not good. This means kubeconfig
flag is available to ALL commands. While this is desirable in the future, this is not supported by all commands yet. This is going to cause a lot of confusions.
Either:
- Move this to the get cluster command only. OR
- Remove this flag entirely and do this in a separate PR.
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.
I moved the flag to the get
command: See: dffda70
service := corev1.Service{} | ||
namespacedName := types.NamespacedName{ | ||
Name: "kubernetes", | ||
Namespace: "default", | ||
} | ||
err := cli.Get(context.TODO(), namespacedName, &service) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to get the kubernetes default service on the cluster. %w", err) | ||
} |
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.
I think it's better to look at the localbuild object instead.
I see you are doing port.Name != "" && strings.HasPrefix(port.Name, "https")
. But this is not guaranteed to be available. For example, if you run the create command with --protocol http
, the https port returned is incorrect.
So I'd rather look at the spec.buildCustomization
field of the localbuild object.
idpbuilder/api/v1alpha1/localbuild_types.go
Lines 52 to 59 in 03559e6
type BuildCustomizationSpec struct { | |
Protocol string `json:"protocol,omitempty"` | |
Host string `json:"host,omitempty"` | |
IngressHost string `json:"ingressHost,omitempty"` | |
Port string `json:"port,omitempty"` | |
UsePathRouting bool `json:"usePathRouting,omitempty"` | |
SelfSignedCert string `json:"selfSignedCert,omitempty"` | |
} |
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.
pkg/cmd/get/clusters.go
Outdated
// Display the total allocated resources | ||
//fmt.Printf(" CPU Requests: %s\n", totalCPU.String()) | ||
//fmt.Printf(" Memory Requests: %s\n", totalMemory.String()) | ||
|
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.
Remove these
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
//logger.Error(err, "failed to get the allocated resources.") | ||
return nil, err | ||
} | ||
aNode.Allocated = allocated |
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.
I don't see aNode
value used for anything here still.
pkg/cmd/get/clusters.go
Outdated
} | ||
|
||
// Populate a list of Kube client for each cluster/context matching a idpbuilder cluster | ||
manager, _ := CreateKubeClientForEachIDPCluster(config, clusters) |
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.
Need to handle error here. If an error is returned and manager is nil, we will panic.
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
…of nodes Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
/e2e |
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.
LGTM