Skip to content
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

Merged
merged 18 commits into from
Dec 2, 2024
Merged

Conversation

cmoulliard
Copy link
Contributor

@cmoulliard cmoulliard commented Nov 14, 2024

  • 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
./idpbuilder -h
Manage reference IDPs

Usage:
  idpbuilder [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  create      (Re)Create an IDP cluster
  delete      Delete an IDP cluster
  get         get information from the cluster
  help        Help about any command
  version     Print idpbuilder version and environment info

Flags:
      --color              Enable colored log messages.
  -h, --help               help for idpbuilder
      --kubePath string    kube config file Path.
  • Command currently shows:
Cluster: my-konflux
URL of the kube API server: https://127.0.0.1:63473
TLS Verify: false
  Node: my-konflux-control-plane
  Internal IP: 10.89.0.2
----------

@cmoulliard
Copy link
Contributor Author

cmoulliard commented Nov 14, 2024

If several clusters/contexts/nodes have been created, then the command will output the following information:

Cluster: dabou
URL of the kube API server: https://127.0.0.1:53369
TLS Verify: false
External Port: 9443

Node: dabou-control-plane
Internal IP: 10.89.0.4
Capacity of the node: 
  cpu                  8
  memory               12.66 GB
  pods                 110
Allocated resources on node:
  CPU Requests: 1050m
  Memory Requests: 380Mi
----------------------------------------
Cluster: my-konflux
URL of the kube API server: https://127.0.0.1:63473
TLS Verify: false
External Port: 8443

Node: my-konflux-control-plane
Internal IP: 10.89.0.2
Capacity of the node: 
  cpu                  8
  memory               12.66 GB
  pods                 110
Allocated resources on node:
  CPU Requests: 2820m
  Memory Requests: 6898Mi
----------------------------------------

@cmoulliard
Copy link
Contributor Author

I refactored the code to show the clusters using a Table

❯ ./idpbuilder get clusters
Nov 15 12:12:21 INFO enabling experimental podman provider 
NAME         EXTERNAL-PORT   KUBE-API                  TLS     KUBE-PORT
my-konflux   8443            https://127.0.0.1:65073   false   6443
test         9443            https://127.0.0.1:53454   false   6443

@nabuskey

@cmoulliard cmoulliard marked this pull request as ready for review November 21, 2024 13:48
@cmoulliard cmoulliard requested a review from a team as a code owner November 21, 2024 13:48
Copy link
Collaborator

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/root.go Outdated Show resolved Hide resolved
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
Copy link
Collaborator

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.

Copy link
Contributor Author

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

pkg/cmd/get/clusters.go Outdated Show resolved Hide resolved
//logger.Error(err, "failed to get the allocated resources.")
return nil, err
}
aNode.Allocated = allocated
Copy link
Collaborator

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?

Copy link
Contributor Author

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 ?

Copy link
Collaborator

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.

Copy link
Contributor Author

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 ;-)

Copy link
Collaborator

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.

Copy link
Contributor Author

@cmoulliard cmoulliard Nov 28, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See: 9fc54e2

@cmoulliard
Copy link
Contributor Author

Can we merge it ? @nabuskey


detectOpt, err := util.DetectKindNodeProvider()
if err != nil {
//logger.Error(err, "failed to detect the provider.")
Copy link
Collaborator

@nabuskey nabuskey Nov 27, 2024

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

Copy link
Contributor Author

@cmoulliard cmoulliard Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comments.

Copy link
Contributor Author

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.")
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Comment on lines +302 to +310
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)
}
Copy link
Collaborator

@nabuskey nabuskey Nov 27, 2024

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.

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"`
}

Copy link
Contributor Author

@cmoulliard cmoulliard Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit f1d03fa & 8f4810c to grab the Localbuild of the cluster

Comment on lines 268 to 271
// Display the total allocated resources
//fmt.Printf(" CPU Requests: %s\n", totalCPU.String())
//fmt.Printf(" Memory Requests: %s\n", totalMemory.String())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these

Copy link
Contributor Author

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
Copy link
Collaborator

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.

}

// Populate a list of Kube client for each cluster/context matching a idpbuilder cluster
manager, _ := CreateKubeClientForEachIDPCluster(config, clusters)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nabuskey
Copy link
Collaborator

nabuskey commented Dec 2, 2024

/e2e

Copy link
Collaborator

@nabuskey nabuskey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cmoulliard cmoulliard merged commit 9925fb3 into cnoe-io:main Dec 2, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants