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

Add PersistentPreRun to the root CLI cmd to set the kube client and cluster details once for all commands #1759

Merged
merged 4 commits into from
Nov 17, 2024

Conversation

RonFed
Copy link
Contributor

@RonFed RonFed commented Nov 15, 2024

Add PersistentPreRun which will be inherited by all sub-commands of the root command.
Perform a client initialzation in that function and set the cluster kind and k8s version as well - so they can be used by all commands. Both the kube client and the cluster details are set on the command context and can be used by all the commands.
The helper function from k8sutils GetKubernetesVersion can't be used outside of the cluster by the CLI since it as using a rest client which states:

// InClusterConfig returns a config object which uses the service account
// kubernetes gives to pods. It's intended for clients that expect to be
// running inside a pod running on kubernetes. It will return ErrNotInCluster
// if called from a process not running in a kubernetes environment.
func InClusterConfig() (*Config, error) {

Hence, removing the use of this function from the CLI, and using the k8s version which was calculated in the PersistentPreRun function.
Before this change odigos upgrade resulted in errors such as:

Syncing customresourcedefinitionsDeleteOldOdigosSystemObjects failed to get k8s version, proceeding.. :unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined ✔
Syncing deploymentsDeleteOldOdigosSystemObjects failed to get k8s version, proceeding.. :unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined ✔
Syncing daemonsetsDeleteOldOdigosSystemObjects failed to get k8s version, proceeding.. :unable to load in-cluster

@RonFed RonFed marked this pull request as ready for review November 16, 2024 08:14
cli/pkg/autodetect/kind.go Outdated Show resolved Hide resolved
cli/pkg/autodetect/kind.go Show resolved Hide resolved
cli/pkg/autodetect/kind.go Outdated Show resolved Hide resolved
cli/pkg/kube/client.go Outdated Show resolved Hide resolved
cli/pkg/kube/client.go Show resolved Hide resolved
cli/pkg/kube/client.go Outdated Show resolved Hide resolved
cli/cmd/install.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@blumamir blumamir left a comment

Choose a reason for hiding this comment

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

🥇

@RonFed RonFed merged commit 148a184 into odigos-io:main Nov 17, 2024
31 checks passed
@RonFed RonFed deleted the cli_k8s_version_once branch November 17, 2024 08:40
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