Skip to content

[tmpnet] Define reusable flags for configuring kubernetes client access #3945

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maru-ava
Copy link
Contributor

@maru-ava maru-ava commented May 7, 2025

PR Chain: tmpnet+kube

This PR chain enables tmpnet to deploy temporary networks to Kubernetes. Early PRs refactor tmpnet to support the addition in #3615 of a new tmpnet node runtime for kube.

Why this should be merged

Previously tmpnetctl start-kind-cluster and the bootstrap-monitor determined their kubeconfig and context separately. Simpler to do it one way and this will be reusable by the kube node runtime.

How this was tested

CI

Need to be documented in RELEASES.md?

N/A

@maru-ava maru-ava self-assigned this May 7, 2025
@Copilot Copilot AI review requested due to automatic review settings May 7, 2025 21:56
@maru-ava maru-ava added the tooling Build, test and development tooling label May 7, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the handling of Kubernetes configuration by introducing reusable flag variables so that both the tmpnetctl command and bootstrap-monitor tests consistently consume kubeconfig settings.

  • Refactored main.go to remove manual kubeconfig flag handling and adopt the new reusable flags.
  • Added a new flags package (kube_config.go) encapsulating kubeconfig flag registration.
  • Updated e2e tests and Taskfile.yml to leverage the new flag definitions.

Reviewed Changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated 1 comment.

File Description
tests/fixture/tmpnet/tmpnetctl/main.go Removed manual flag registration; replaced with reusable kubeconfig flag handling.
tests/fixture/tmpnet/flags/kube_config.go Introduced a new reusable flag set for kubeconfig configuration.
tests/fixture/bootstrapmonitor/e2e/e2e_test.go Updated kubeconfig retrieval to use the new flag variables.
Taskfile.yml Added a new ginkgo-build task to run tests against the current working directory.
Files not reviewed (3)
  • flake.nix: Language not supported
  • scripts/start_kind_cluster.sh: Language not supported
  • scripts/tests.e2e.bootstrap_monitor.sh: Language not supported
Comments suppressed due to low confidence (1)

tests/fixture/tmpnet/flags/kube_config.go:47

  • [nitpick] The type 'varFunc[string]' is not defined in this diff and may be unclear to readers. Consider adding documentation or a comment clarifying its purpose and definition.
func (v *KubeconfigVars) register(stringVar varFunc[string], docPrefix string) {

@maru-ava maru-ava moved this to In Progress 🏗️ in avalanchego May 7, 2025
@maru-ava maru-ava moved this from In Progress 🏗️ to Ready 🚦 in avalanchego May 7, 2025
@@ -89,6 +89,10 @@ tasks:
desc: Generates protobuf
cmd: ./scripts/protobuf_codegen.sh

ginkgo-build:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason ginkgo build . is no longer working, this task enables invoking ginkgo from anywhere in the tree against the cwd rather than having to use a root-based path.

@@ -45,6 +45,7 @@

# Kube tools
kubectl # Kubernetes CLI
k9s # Kubernetes TUI
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handy for diagnosing kube issues

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This script is reused in subsequent PRs

@maru-ava maru-ava force-pushed the tmpnet-kubeconfig-flags branch from 0ae4351 to 29d35d9 Compare May 7, 2025 22:01
@@ -221,6 +222,6 @@ func getLatestImageDetails(

func getClientset(log logging.Logger) (*kubernetes.Clientset, error) {
log.Info("Initializing clientset")
kubeConfigPath := os.Getenv("KUBECONFIG")
kubeConfigPath := os.Getenv(flags.KubeConfigPathEnvVar)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the bootstrap-monitor doesn't accept flags, it's only intended to run in kubernetes with an in-cluster config.

@maru-ava maru-ava changed the title [tmpnet] Define reusable flags for configuring kubernetes [tmpnet] Define reusable flags for configuring kubernetes client access May 7, 2025
Comment on lines 6 to 14
START_CLUSTER_ARGS=()
for arg in "$@"; do
if [[ "${arg}" =~ "--kubeconfig" || "${arg}" =~ "--kubeconfig-context" ]]; then
START_CLUSTER_ARGS+=("${arg}")
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks wrong to me. If you invoke this with "start_kind_cluster --kubeconfig something" then it will invoke tmpnetctl with only "--kubeconfig" and not supply the "something" argument.

Might work as long as you always invoke with "--kubeconfig=something", but I've never seen commands invoked like that.

Copy link
Contributor Author

@maru-ava maru-ava May 8, 2025

Choose a reason for hiding this comment

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

I've never seen commands invoked like that.

My shell history would like a word with you...

This is a test script that works without any arguments, accepting --kubeconfig and --kubeconfig-context is a convenience. I'm not sure it's too much to ask to require the form --arg=value, but I take your point that it should be documented.

Copy link
Contributor

Choose a reason for hiding this comment

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

My shell history would like a word with you...
🤣

This would have definitely express the intent:

if [[ "${arg}" =~ "--kubeconfig=" || "${arg}" =~ "--kubeconfig-context=" ]]; then

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

Copy link
Contributor

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

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

👍

maru-ava added 3 commits May 9, 2025 18:50
Previously `tmpnetctl start-kind-cluster` and the bootstrap-monitor
determined their kubeconfig and context separately. Simpler to do it
one way and this will be reusable by the kube node runtime.
@maru-ava maru-ava force-pushed the tmpnet-kubeconfig-flags branch from 98c745c to 55a18b1 Compare May 9, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tooling Build, test and development tooling
Projects
Status: Ready 🚦
Development

Successfully merging this pull request may close these issues.

4 participants