Skip to content

Commit 7d5a829

Browse files
Merge pull request llm-d-incubation#197 from osswangxining/addKubernetesClientFlags
create AddKubernetesClientFlags func within pkg/common
2 parents 886b603 + be68b50 commit 7d5a829

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

pkg/common/flags.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2025 The llm-d Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package common
18+
19+
import (
20+
"github.com/spf13/pflag"
21+
"k8s.io/client-go/tools/clientcmd"
22+
)
23+
24+
// AddKubernetesClientFlags adds Kubernetes client configuration flags to the provided FlagSet.
25+
// This function allows users to specify kubeconfig file path, context, user, cluster, and namespace
26+
// through command line flags for Kubernetes client configuration.
27+
//
28+
// Parameters:
29+
// - flags: A pflag.FlagSet to which the Kubernetes client flags will be added
30+
// - loadingRules: A pointer to clientcmd.ClientConfigLoadingRules that contains rules for loading kubeconfig
31+
// - overrides: A pointer to clientcmd.ConfigOverrides that contains configuration overrides
32+
func AddKubernetesClientFlags(flags pflag.FlagSet, loadingRules *clientcmd.ClientConfigLoadingRules, overrides *clientcmd.ConfigOverrides) {
33+
if loadingRules == nil {
34+
return
35+
}
36+
if overrides == nil {
37+
return
38+
}
39+
40+
flags.StringVar(&loadingRules.ExplicitPath, "kubeconfig", loadingRules.ExplicitPath, "Path to the kubeconfig file to use")
41+
flags.StringVar(&overrides.CurrentContext, "context", overrides.CurrentContext, "The name of the kubeconfig context to use")
42+
flags.StringVar(&overrides.Context.AuthInfo, "user", overrides.Context.AuthInfo, "The name of the kubeconfig user to use")
43+
flags.StringVar(&overrides.Context.Cluster, "cluster", overrides.Context.Cluster, "The name of the kubeconfig cluster to use")
44+
flags.StringVarP(&overrides.Context.Namespace, "namespace", "n", overrides.Context.Namespace, "The name of the Kubernetes Namespace to work in (NOT optional)")
45+
}

0 commit comments

Comments
 (0)