-
Notifications
You must be signed in to change notification settings - Fork 751
[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
Changes from all commits
dfa5bc6
f3a6bc5
dea4e91
2977b0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
|
||
# Kube tools | ||
kubectl # Kubernetes CLI | ||
k9s # Kubernetes TUI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handy for diagnosing kube issues |
||
kind # Kubernetes-in-Docker | ||
kubernetes-helm # Helm CLI (Kubernetes package manager) | ||
self.packages.${system}.kind-with-registry # Script installing kind configured with a local registry | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script is reused in subsequent PRs |
||
|
||
set -euo pipefail | ||
|
||
# --kubeconfig and --kubeconfig-context should be provided in the form --arg=value | ||
# to work with the simplistic mechanism enabling flag reuse. | ||
|
||
# Enable reuse of the arguments to ginkgo relevant to starting a cluster | ||
START_CLUSTER_ARGS=() | ||
for arg in "$@"; do | ||
if [[ "${arg}" =~ "--kubeconfig=" || "${arg}" =~ "--kubeconfig-context=" ]]; then | ||
START_CLUSTER_ARGS+=("${arg}") | ||
fi | ||
done | ||
./bin/tmpnetctl start-kind-cluster "${START_CLUSTER_ARGS[@]}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package flags | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/pflag" | ||
|
||
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet" | ||
) | ||
|
||
const KubeconfigPathEnvVar = "KUBECONFIG" | ||
|
||
type KubeconfigVars struct { | ||
Path string | ||
Context string | ||
} | ||
|
||
// NewKubeconfigFlagVars registers kubeconfig flag variables for stdlib flag | ||
func NewKubeconfigFlagVars() *KubeconfigVars { | ||
return newKubeconfigFlagVars("") | ||
} | ||
|
||
// internal method enabling configuration of the doc prefix | ||
func newKubeconfigFlagVars(docPrefix string) *KubeconfigVars { | ||
v := &KubeconfigVars{} | ||
v.register(flag.StringVar, docPrefix) | ||
return v | ||
} | ||
|
||
// NewKubeconfigFlagSetVars registers kubeconfig flag variables for pflag | ||
func NewKubeconfigFlagSetVars(flagSet *pflag.FlagSet) *KubeconfigVars { | ||
return newKubeconfigFlagSetVars(flagSet, "") | ||
} | ||
|
||
// internal method enabling configuration of the doc prefix | ||
func newKubeconfigFlagSetVars(flagSet *pflag.FlagSet, docPrefix string) *KubeconfigVars { | ||
v := &KubeconfigVars{} | ||
v.register(flagSet.StringVar, docPrefix) | ||
return v | ||
} | ||
|
||
func (v *KubeconfigVars) register(stringVar varFunc[string], docPrefix string) { | ||
stringVar( | ||
&v.Path, | ||
"kubeconfig", | ||
tmpnet.GetEnvWithDefault(KubeconfigPathEnvVar, os.ExpandEnv("$HOME/.kube/config")), | ||
docPrefix+fmt.Sprintf( | ||
"The path to a kubernetes configuration file for the target cluster. Also possible to configure via the %s env variable.", | ||
KubeconfigPathEnvVar, | ||
), | ||
) | ||
stringVar( | ||
&v.Context, | ||
"kubeconfig-context", | ||
"", | ||
docPrefix+"The optional kubeconfig context to use", | ||
) | ||
} |
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.
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.