mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update K8s packages to v0.32.1
Update K8s packages in go.mod to v0.32.1 Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
2
vendor/k8s.io/client-go/tools/clientcmd/api/latest/latest.go
generated
vendored
2
vendor/k8s.io/client-go/tools/clientcmd/api/latest/latest.go
generated
vendored
@ -50,7 +50,7 @@ func init() {
|
||||
Scheme = runtime.NewScheme()
|
||||
utilruntime.Must(api.AddToScheme(Scheme))
|
||||
utilruntime.Must(v1.AddToScheme(Scheme))
|
||||
yamlSerializer := json.NewYAMLSerializer(json.DefaultMetaFactory, Scheme, Scheme)
|
||||
yamlSerializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, Scheme, Scheme, json.SerializerOptions{Yaml: true})
|
||||
Codec = versioning.NewDefaultingCodecForScheme(
|
||||
Scheme,
|
||||
yamlSerializer,
|
||||
|
76
vendor/k8s.io/client-go/tools/clientcmd/client_config.go
generated
vendored
76
vendor/k8s.io/client-go/tools/clientcmd/client_config.go
generated
vendored
@ -29,8 +29,6 @@ import (
|
||||
clientauth "k8s.io/client-go/tools/auth"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -241,45 +239,37 @@ func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mergo.Merge(clientConfig, userAuthPartialConfig, mergo.WithOverride)
|
||||
|
||||
serverAuthPartialConfig, err := getServerIdentificationPartialConfig(configAuthInfo, configClusterInfo)
|
||||
if err != nil {
|
||||
if err := merge(clientConfig, userAuthPartialConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
serverAuthPartialConfig := getServerIdentificationPartialConfig(configClusterInfo)
|
||||
if err := merge(clientConfig, serverAuthPartialConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mergo.Merge(clientConfig, serverAuthPartialConfig, mergo.WithOverride)
|
||||
}
|
||||
|
||||
return clientConfig, nil
|
||||
}
|
||||
|
||||
// clientauth.Info object contain both user identification and server identification. We want different precedence orders for
|
||||
// both, so we have to split the objects and merge them separately
|
||||
// we want this order of precedence for the server identification
|
||||
// 1. configClusterInfo (the final result of command line flags and merged .kubeconfig files)
|
||||
// 2. configAuthInfo.auth-path (this file can contain information that conflicts with #1, and we want #1 to win the priority)
|
||||
// 3. load the ~/.kubernetes_auth file as a default
|
||||
func getServerIdentificationPartialConfig(configAuthInfo clientcmdapi.AuthInfo, configClusterInfo clientcmdapi.Cluster) (*restclient.Config, error) {
|
||||
mergedConfig := &restclient.Config{}
|
||||
// both, so we have to split the objects and merge them separately.
|
||||
|
||||
// configClusterInfo holds the information identify the server provided by .kubeconfig
|
||||
// getServerIdentificationPartialConfig extracts server identification information from configClusterInfo
|
||||
// (the final result of command line flags and merged .kubeconfig files).
|
||||
func getServerIdentificationPartialConfig(configClusterInfo clientcmdapi.Cluster) *restclient.Config {
|
||||
configClientConfig := &restclient.Config{}
|
||||
configClientConfig.CAFile = configClusterInfo.CertificateAuthority
|
||||
configClientConfig.CAData = configClusterInfo.CertificateAuthorityData
|
||||
configClientConfig.Insecure = configClusterInfo.InsecureSkipTLSVerify
|
||||
configClientConfig.ServerName = configClusterInfo.TLSServerName
|
||||
mergo.Merge(mergedConfig, configClientConfig, mergo.WithOverride)
|
||||
|
||||
return mergedConfig, nil
|
||||
return configClientConfig
|
||||
}
|
||||
|
||||
// clientauth.Info object contain both user identification and server identification. We want different precedence orders for
|
||||
// both, so we have to split the objects and merge them separately
|
||||
// we want this order of precedence for user identification
|
||||
// 1. configAuthInfo minus auth-path (the final result of command line flags and merged .kubeconfig files)
|
||||
// 2. configAuthInfo.auth-path (this file can contain information that conflicts with #1, and we want #1 to win the priority)
|
||||
// 3. if there is not enough information to identify the user, load try the ~/.kubernetes_auth file
|
||||
// 4. if there is not enough information to identify the user, prompt if possible
|
||||
// getUserIdentificationPartialConfig extracts user identification information from configAuthInfo
|
||||
// (the final result of command line flags and merged .kubeconfig files);
|
||||
// if the information available there is insufficient, it prompts (if possible) for additional information.
|
||||
func (config *DirectClientConfig) getUserIdentificationPartialConfig(configAuthInfo clientcmdapi.AuthInfo, fallbackReader io.Reader, persistAuthConfig restclient.AuthProviderConfigPersister, configClusterInfo clientcmdapi.Cluster) (*restclient.Config, error) {
|
||||
mergedConfig := &restclient.Config{}
|
||||
|
||||
@ -338,8 +328,12 @@ func (config *DirectClientConfig) getUserIdentificationPartialConfig(configAuthI
|
||||
promptedConfig := makeUserIdentificationConfig(*promptedAuthInfo)
|
||||
previouslyMergedConfig := mergedConfig
|
||||
mergedConfig = &restclient.Config{}
|
||||
mergo.Merge(mergedConfig, promptedConfig, mergo.WithOverride)
|
||||
mergo.Merge(mergedConfig, previouslyMergedConfig, mergo.WithOverride)
|
||||
if err := merge(mergedConfig, promptedConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := merge(mergedConfig, previouslyMergedConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.promptedCredentials.username = mergedConfig.Username
|
||||
config.promptedCredentials.password = mergedConfig.Password
|
||||
}
|
||||
@ -347,7 +341,7 @@ func (config *DirectClientConfig) getUserIdentificationPartialConfig(configAuthI
|
||||
return mergedConfig, nil
|
||||
}
|
||||
|
||||
// makeUserIdentificationFieldsConfig returns a client.Config capable of being merged using mergo for only user identification information
|
||||
// makeUserIdentificationFieldsConfig returns a client.Config capable of being merged for only user identification information
|
||||
func makeUserIdentificationConfig(info clientauth.Info) *restclient.Config {
|
||||
config := &restclient.Config{}
|
||||
config.Username = info.User
|
||||
@ -507,12 +501,16 @@ func (config *DirectClientConfig) getContext() (clientcmdapi.Context, error) {
|
||||
|
||||
mergedContext := clientcmdapi.NewContext()
|
||||
if configContext, exists := contexts[contextName]; exists {
|
||||
mergo.Merge(mergedContext, configContext, mergo.WithOverride)
|
||||
if err := merge(mergedContext, configContext); err != nil {
|
||||
return clientcmdapi.Context{}, err
|
||||
}
|
||||
} else if required {
|
||||
return clientcmdapi.Context{}, fmt.Errorf("context %q does not exist", contextName)
|
||||
}
|
||||
if config.overrides != nil {
|
||||
mergo.Merge(mergedContext, config.overrides.Context, mergo.WithOverride)
|
||||
if err := merge(mergedContext, &config.overrides.Context); err != nil {
|
||||
return clientcmdapi.Context{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return *mergedContext, nil
|
||||
@ -525,12 +523,16 @@ func (config *DirectClientConfig) getAuthInfo() (clientcmdapi.AuthInfo, error) {
|
||||
|
||||
mergedAuthInfo := clientcmdapi.NewAuthInfo()
|
||||
if configAuthInfo, exists := authInfos[authInfoName]; exists {
|
||||
mergo.Merge(mergedAuthInfo, configAuthInfo, mergo.WithOverride)
|
||||
if err := merge(mergedAuthInfo, configAuthInfo); err != nil {
|
||||
return clientcmdapi.AuthInfo{}, err
|
||||
}
|
||||
} else if required {
|
||||
return clientcmdapi.AuthInfo{}, fmt.Errorf("auth info %q does not exist", authInfoName)
|
||||
}
|
||||
if config.overrides != nil {
|
||||
mergo.Merge(mergedAuthInfo, config.overrides.AuthInfo, mergo.WithOverride)
|
||||
if err := merge(mergedAuthInfo, &config.overrides.AuthInfo); err != nil {
|
||||
return clientcmdapi.AuthInfo{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return *mergedAuthInfo, nil
|
||||
@ -543,15 +545,21 @@ func (config *DirectClientConfig) getCluster() (clientcmdapi.Cluster, error) {
|
||||
|
||||
mergedClusterInfo := clientcmdapi.NewCluster()
|
||||
if config.overrides != nil {
|
||||
mergo.Merge(mergedClusterInfo, config.overrides.ClusterDefaults, mergo.WithOverride)
|
||||
if err := merge(mergedClusterInfo, &config.overrides.ClusterDefaults); err != nil {
|
||||
return clientcmdapi.Cluster{}, err
|
||||
}
|
||||
}
|
||||
if configClusterInfo, exists := clusterInfos[clusterInfoName]; exists {
|
||||
mergo.Merge(mergedClusterInfo, configClusterInfo, mergo.WithOverride)
|
||||
if err := merge(mergedClusterInfo, configClusterInfo); err != nil {
|
||||
return clientcmdapi.Cluster{}, err
|
||||
}
|
||||
} else if required {
|
||||
return clientcmdapi.Cluster{}, fmt.Errorf("cluster %q does not exist", clusterInfoName)
|
||||
}
|
||||
if config.overrides != nil {
|
||||
mergo.Merge(mergedClusterInfo, config.overrides.ClusterInfo, mergo.WithOverride)
|
||||
if err := merge(mergedClusterInfo, &config.overrides.ClusterInfo); err != nil {
|
||||
return clientcmdapi.Cluster{}, err
|
||||
}
|
||||
}
|
||||
|
||||
// * An override of --insecure-skip-tls-verify=true and no accompanying CA/CA data should clear already-set CA/CA data
|
||||
|
17
vendor/k8s.io/client-go/tools/clientcmd/loader.go
generated
vendored
17
vendor/k8s.io/client-go/tools/clientcmd/loader.go
generated
vendored
@ -24,7 +24,6 @@ import (
|
||||
goruntime "runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@ -248,7 +247,9 @@ func (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error) {
|
||||
mapConfig := clientcmdapi.NewConfig()
|
||||
|
||||
for _, kubeconfig := range kubeconfigs {
|
||||
mergo.Merge(mapConfig, kubeconfig, mergo.WithOverride)
|
||||
if err := merge(mapConfig, kubeconfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// merge all of the struct values in the reverse order so that priority is given correctly
|
||||
@ -256,14 +257,20 @@ func (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error) {
|
||||
nonMapConfig := clientcmdapi.NewConfig()
|
||||
for i := len(kubeconfigs) - 1; i >= 0; i-- {
|
||||
kubeconfig := kubeconfigs[i]
|
||||
mergo.Merge(nonMapConfig, kubeconfig, mergo.WithOverride)
|
||||
if err := merge(nonMapConfig, kubeconfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// since values are overwritten, but maps values are not, we can merge the non-map config on top of the map config and
|
||||
// get the values we expect.
|
||||
config := clientcmdapi.NewConfig()
|
||||
mergo.Merge(config, mapConfig, mergo.WithOverride)
|
||||
mergo.Merge(config, nonMapConfig, mergo.WithOverride)
|
||||
if err := merge(config, mapConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := merge(config, nonMapConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if rules.ResolvePaths() {
|
||||
if err := ResolveLocalPaths(config); err != nil {
|
||||
|
121
vendor/k8s.io/client-go/tools/clientcmd/merge.go
generated
vendored
Normal file
121
vendor/k8s.io/client-go/tools/clientcmd/merge.go
generated
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright 2024 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package clientcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// recursively merges src into dst:
|
||||
// - non-pointer struct fields with any exported fields are recursively merged
|
||||
// - non-pointer struct fields with only unexported fields prefer src if the field is non-zero
|
||||
// - maps are shallow merged with src keys taking priority over dst
|
||||
// - non-zero src fields encountered during recursion that are not maps or structs overwrite and recursion stops
|
||||
func merge[T any](dst, src *T) error {
|
||||
if dst == nil {
|
||||
return fmt.Errorf("cannot merge into nil pointer")
|
||||
}
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
return mergeValues(nil, reflect.ValueOf(dst).Elem(), reflect.ValueOf(src).Elem())
|
||||
}
|
||||
|
||||
func mergeValues(fieldNames []string, dst, src reflect.Value) error {
|
||||
dstType := dst.Type()
|
||||
// no-op if we can't read the src
|
||||
if !src.IsValid() {
|
||||
return nil
|
||||
}
|
||||
// sanity check types match
|
||||
if srcType := src.Type(); dstType != srcType {
|
||||
return fmt.Errorf("cannot merge mismatched types (%s, %s) at %s", dstType, srcType, strings.Join(fieldNames, "."))
|
||||
}
|
||||
|
||||
switch dstType.Kind() {
|
||||
case reflect.Struct:
|
||||
if hasExportedField(dstType) {
|
||||
// recursively merge
|
||||
for i, n := 0, dstType.NumField(); i < n; i++ {
|
||||
if err := mergeValues(append(fieldNames, dstType.Field(i).Name), dst.Field(i), src.Field(i)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if dst.CanSet() {
|
||||
// If all fields are unexported, overwrite with src.
|
||||
// Using src.IsZero() would make more sense but that's not what mergo did.
|
||||
dst.Set(src)
|
||||
}
|
||||
|
||||
case reflect.Map:
|
||||
if dst.CanSet() && !src.IsZero() {
|
||||
// initialize dst if needed
|
||||
if dst.IsZero() {
|
||||
dst.Set(reflect.MakeMap(dstType))
|
||||
}
|
||||
// shallow-merge overwriting dst keys with src keys
|
||||
for _, mapKey := range src.MapKeys() {
|
||||
dst.SetMapIndex(mapKey, src.MapIndex(mapKey))
|
||||
}
|
||||
}
|
||||
|
||||
case reflect.Slice:
|
||||
if dst.CanSet() && src.Len() > 0 {
|
||||
// overwrite dst with non-empty src slice
|
||||
dst.Set(src)
|
||||
}
|
||||
|
||||
case reflect.Pointer:
|
||||
if dst.CanSet() && !src.IsZero() {
|
||||
// overwrite dst with non-zero values for other types
|
||||
if dstType.Elem().Kind() == reflect.Struct {
|
||||
// use struct pointer as-is
|
||||
dst.Set(src)
|
||||
} else {
|
||||
// shallow-copy non-struct pointer (interfaces, primitives, etc)
|
||||
dst.Set(reflect.New(dstType.Elem()))
|
||||
dst.Elem().Set(src.Elem())
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
if dst.CanSet() && !src.IsZero() {
|
||||
// overwrite dst with non-zero values for other types
|
||||
dst.Set(src)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// hasExportedField returns true if the given type has any exported fields,
|
||||
// or if it has any anonymous/embedded struct fields with exported fields
|
||||
func hasExportedField(dstType reflect.Type) bool {
|
||||
for i, n := 0, dstType.NumField(); i < n; i++ {
|
||||
field := dstType.Field(i)
|
||||
if field.Anonymous && field.Type.Kind() == reflect.Struct {
|
||||
if hasExportedField(dstType.Field(i).Type) {
|
||||
return true
|
||||
}
|
||||
} else if len(field.PkgPath) == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user