getCluster returns the clientcmdapi.Cluster, or an error if a required cluster is not found.
()
| 438 | |
| 439 | // getCluster returns the clientcmdapi.Cluster, or an error if a required cluster is not found. |
| 440 | func (config *DirectClientConfig) getCluster() (clientcmdapi.Cluster, error) { |
| 441 | clusterInfos := config.config.Clusters |
| 442 | clusterInfoName, required := config.getClusterName() |
| 443 | |
| 444 | mergedClusterInfo := clientcmdapi.NewCluster() |
| 445 | mergo.MergeWithOverwrite(mergedClusterInfo, config.overrides.ClusterDefaults) |
| 446 | if configClusterInfo, exists := clusterInfos[clusterInfoName]; exists { |
| 447 | mergo.MergeWithOverwrite(mergedClusterInfo, configClusterInfo) |
| 448 | } else if required { |
| 449 | return clientcmdapi.Cluster{}, fmt.Errorf("cluster %q does not exist", clusterInfoName) |
| 450 | } |
| 451 | mergo.MergeWithOverwrite(mergedClusterInfo, config.overrides.ClusterInfo) |
| 452 | // An override of --insecure-skip-tls-verify=true and no accompanying CA/CA data should clear already-set CA/CA data |
| 453 | // otherwise, a kubeconfig containing a CA reference would return an error that "CA and insecure-skip-tls-verify couldn't both be set" |
| 454 | caLen := len(config.overrides.ClusterInfo.CertificateAuthority) |
| 455 | caDataLen := len(config.overrides.ClusterInfo.CertificateAuthorityData) |
| 456 | if config.overrides.ClusterInfo.InsecureSkipTLSVerify && caLen == 0 && caDataLen == 0 { |
| 457 | mergedClusterInfo.CertificateAuthority = "" |
| 458 | mergedClusterInfo.CertificateAuthorityData = nil |
| 459 | } |
| 460 | |
| 461 | return *mergedClusterInfo, nil |
| 462 | } |
| 463 | |
| 464 | // inClusterClientConfig makes a config that will work from within a kubernetes cluster container environment. |
| 465 | // Can take options overrides for flags explicitly provided to the command inside the cluster container. |
no test coverage detected