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

Kubernetes Config Update: Prioritize InClusterConfig function #3584

Merged
merged 19 commits into from
Jan 26, 2024

Conversation

Kalaiselvi84
Copy link
Contributor

What type of PR is this?

Uncomment only one /kind <> line, press enter to put that in a new line, and remove leading whitespace from that line:

/kind breaking
/kind bug
/kind cleanup
/kind documentation

/kind feature

/kind hotfix
/kind release

What this PR does / Why we need it:

Which issue(s) this PR fixes:

Closes #3582

Special notes for your reviewer:

@github-actions github-actions bot added kind/feature New features for Agones size/S labels Jan 9, 2024
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 79f320f4-3551-4c3d-8e89-17592630bc46

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@Kalaiselvi84 Kalaiselvi84 marked this pull request as draft January 9, 2024 23:30
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 3b3f4d7c-36a3-4026-9286-5d164fd1131d

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 399e2dc6-4959-42c4-91da-d069509a856f

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

pkg/util/k8sconfig/k8s_client_config.go Outdated Show resolved Hide resolved

// InClusterBuildConfig is a helper function that builds configs by trying the InClusterConfig().
// If InClusterConfig is unsuccessful, it falls back to BuildConfigFromFlags.
func InClusterBuildConfig(masterURL, kubeconfigPath string) (*restclient.Config, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func InClusterBuildConfig(masterURL, kubeconfigPath string) (*restclient.Config, error) {
func InClusterBuildConfig(kubeconfigPath string) (*restclient.Config, error) {

Since we never use a masterURL other than "" ?

vendor/k8s.io/client-go/tools/clientcmd/client_config.go Outdated Show resolved Hide resolved
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: d19c02b8-8e6f-4387-8a4d-e70b001ab137

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-e762019-amd64

@Kalaiselvi84 Kalaiselvi84 marked this pull request as ready for review January 12, 2024 02:10
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: c2c52f0e-d2b3-4301-99ab-c436a68e4cf6

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-87698de-amd64

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 5baea74b-7bf5-4912-9492-1ef422c6e09a

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-6ec1577-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Other than a small nit, this LGTM.

@roberthbailey any issues on your end?

// or a kubeconfigPath. These parameters are passed in as command line flags for cluster
// components. If neither masterUrl or kubeconfigPath are passed,
// the function logs a warning and falls back to a default configuration
func BuildCustomConfigFromFlags(masterURL, kubeconfigPath string) (*restclient.Config, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Small thing, but since this function isn't used anywhere else - any reason not to have the content be inline with InClusterBuildConfig(...) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged the two functions and removed the masterURL from the return statement. Now the return statement is:

return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
    &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
    &clientcmd.ConfigOverrides{}).ClientConfig()

Would this approach look good?

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 9b818f54-8bf0-47f9-8725-0c14d1513ec8

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 1010687c-89d7-4139-81f8-1af3bf7aecaa

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-233fa64-amd64

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 0a658c43-ca58-4d2b-8f31-81aa73184865

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-0779346-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Approach looks good - just saw one thing that needs tweaking.

pkg/util/runtime/runtime.go Outdated Show resolved Hide resolved
pkg/util/runtime/runtime.go Outdated Show resolved Hide resolved
// if the kubeconfig fails BuildConfigFromFlags will try in cluster config
clientConf, err := clientcmd.BuildConfigFromFlags("", ctlConf.KubeConfig)
// if the kubeconfig fails InClusterBuildConfig will try in cluster config
clientConf, err := runtime.InClusterBuildConfig(logger.WithFields(logrus.Fields{}), ctlConf.KubeConfig)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
clientConf, err := runtime.InClusterBuildConfig(logger.WithFields(logrus.Fields{}), ctlConf.KubeConfig)
clientConf, err := runtime.InClusterBuildConfig(logger, ctlConf.KubeConfig)

Should be sufficient, and same for the other instances where there is already a global logger in place.

@@ -81,7 +81,8 @@ type Framework struct {
}

func newFramework(kubeconfig string, qps float32, burst int) (*Framework, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
logger := logrus.New()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger := logrus.New()
logger = runtime.NewLoggerWithSource("framework")

Just to be consistent.

@@ -81,7 +81,8 @@ type Framework struct {
}

func newFramework(kubeconfig string, qps float32, burst int) (*Framework, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
logger := logrus.New()
config, err := runtime.InClusterBuildConfig(logger.WithFields(logrus.Fields{}), kubeconfig)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
config, err := runtime.InClusterBuildConfig(logger.WithFields(logrus.Fields{}), kubeconfig)
config, err := runtime.InClusterBuildConfig(logger, kubeconfig)

@@ -49,8 +51,9 @@ func main() {
if *pod == "" {
log.Fatal("--pod must be non-empty")
}
logger := logrus.New()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger := logrus.New()
logger = runtime.NewLoggerWithSource("main")

To be consistent. Might even switch out the log. below to logger to be nice and clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the changes are in place per your suggestion👍

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 809bb667-f608-4832-a100-c82ea7d3f4a2

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 137b4f01-5272-47aa-aa55-e17ac978d6fb

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-4d2b365-amd64

@@ -45,22 +45,23 @@ func main() {
namespace := flag.String("namespace", "default", "Namespace (defaults to `default`)")
pod := flag.String("pod", "", "Pod name (required)")
flag.Parse()
logger := runtime.NewLoggerWithSource("main")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger := runtime.NewLoggerWithSource("main")
logger := runtime.NewLoggerWithSource("evictpod")

Minor of minor tweak (since the file is "evictpod" not "main"), but otherwise, this looks good to go for me.

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

LGTM!

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 1cd9f46f-acb2-4a02-8770-076166695025

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3584/head:pr_3584 && git checkout pr_3584
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.38.0-dev-f81235c-amd64

@markmandel markmandel merged commit f369bc2 into googleforgames:main Jan 26, 2024
4 checks passed
@Kalaiselvi84 Kalaiselvi84 deleted the pr-3582 branch March 15, 2024 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New features for Agones size/M size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the way we initialize the kubernetes client to prevent spurious log warnings
4 participants