mirror of
https://github.com/fluxcd/flux2.git
synced 2026-04-20 18:45:43 +00:00
Use k8s.io/cli-runtime for kubernetes flags
Signed-off-by: Jakob Schrettenbrunner <jakob.schrettenbrunner@telekom.de>
This commit is contained in:
parent
0b133ca9f2
commit
ca7d2e783f
48 changed files with 172 additions and 197 deletions
|
|
@ -26,9 +26,9 @@ import (
|
|||
|
||||
"github.com/fluxcd/pkg/ssa"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/kustomization"
|
||||
|
|
@ -36,12 +36,12 @@ import (
|
|||
|
||||
// Apply is the equivalent of 'kubectl apply --server-side -f'.
|
||||
// If the given manifest is a kustomization.yaml, then apply performs the equivalent of 'kubectl apply --server-side -k'.
|
||||
func Apply(ctx context.Context, kubeConfigPath string, kubeContext string, manifestPath string) (string, error) {
|
||||
cfg, err := KubeConfig(kubeConfigPath, kubeContext)
|
||||
func Apply(ctx context.Context, rcg genericclioptions.RESTClientGetter, manifestPath string) (string, error) {
|
||||
cfg, err := KubeConfig(rcg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
restMapper, err := apiutil.NewDynamicRESTMapper(cfg)
|
||||
restMapper, err := rcg.ToRESTMapper()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ import (
|
|||
apiruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
sigyaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
|
|
@ -107,22 +107,8 @@ func ExecKubectlCommand(ctx context.Context, mode ExecMode, kubeConfigPath strin
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func ClientConfig(kubeConfigPath string, kubeContext string) clientcmd.ClientConfig {
|
||||
configFiles := SplitKubeConfigPath(kubeConfigPath)
|
||||
configOverrides := clientcmd.ConfigOverrides{}
|
||||
|
||||
if len(kubeContext) > 0 {
|
||||
configOverrides.CurrentContext = kubeContext
|
||||
}
|
||||
|
||||
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{Precedence: configFiles},
|
||||
&configOverrides,
|
||||
)
|
||||
}
|
||||
|
||||
func KubeConfig(kubeConfigPath string, kubeContext string) (*rest.Config, error) {
|
||||
cfg, err := ClientConfig(kubeConfigPath, kubeContext).ClientConfig()
|
||||
func KubeConfig(rcg genericclioptions.RESTClientGetter) (*rest.Config, error) {
|
||||
cfg, err := rcg.ToRESTConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubernetes configuration load failed: %w", err)
|
||||
}
|
||||
|
|
@ -152,10 +138,10 @@ func NewScheme() *apiruntime.Scheme {
|
|||
return scheme
|
||||
}
|
||||
|
||||
func KubeClient(kubeConfigPath string, kubeContext string) (client.WithWatch, error) {
|
||||
cfg, err := KubeConfig(kubeConfigPath, kubeContext)
|
||||
func KubeClient(rcg genericclioptions.RESTClientGetter) (client.WithWatch, error) {
|
||||
cfg, err := rcg.ToRESTConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubernetes client initialization failed: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
scheme := NewScheme()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue