Skip to content

Commit d79694c

Browse files
authored
Merge pull request kubernetes-sigs#10799 from vincepri/cabpk-generate-file-discovery
✨ Allow CAPBK to generate JoinConfiguration discovery kubeconfig
2 parents 0cdfb88 + 1169522 commit d79694c

28 files changed

+1336
-71
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,11 @@ generate-go-conversions-kubeadm-bootstrap: $(CONVERSION_GEN) ## Generate convers
492492
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt \
493493
./internal/apis/bootstrap/kubeadm/v1alpha3 \
494494
./internal/apis/bootstrap/kubeadm/v1alpha4
495-
$(MAKE) clean-generated-conversions SRC_DIRS="./bootstrap/kubeadm/types/upstreamv1beta2,./bootstrap/kubeadm/types/upstreamv1beta3,./bootstrap/kubeadm/types/upstreamv1beta4"
495+
$(MAKE) clean-generated-conversions SRC_DIRS="./bootstrap/kubeadm/types/upstreamv1beta1,./bootstrap/kubeadm/types/upstreamv1beta2,./bootstrap/kubeadm/types/upstreamv1beta3,./bootstrap/kubeadm/types/upstreamv1beta4"
496496
$(CONVERSION_GEN) \
497497
--output-file=zz_generated.conversion.go \
498498
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt \
499+
./bootstrap/kubeadm/types/upstreamv1beta1 \
499500
./bootstrap/kubeadm/types/upstreamv1beta2 \
500501
./bootstrap/kubeadm/types/upstreamv1beta3 \
501502
./bootstrap/kubeadm/types/upstreamv1beta4

bootstrap/kubeadm/api/v1beta1/kubeadm_types.go

+131
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,137 @@ type BootstrapTokenDiscovery struct {
512512
type FileDiscovery struct {
513513
// KubeConfigPath is used to specify the actual file path or URL to the kubeconfig file from which to load cluster information
514514
KubeConfigPath string `json:"kubeConfigPath"`
515+
516+
// KubeConfig is used (optionally) to generate a KubeConfig based on the KubeadmConfig's information.
517+
// The file is generated at the path specified in KubeConfigPath.
518+
//
519+
// Host address (server field) information is automatically populated based on the Cluster's ControlPlaneEndpoint.
520+
// Certificate Authority (certificate-authority-data field) is gathered from the cluster's CA secret.
521+
//
522+
// +optional
523+
KubeConfig *FileDiscoveryKubeConfig `json:"kubeConfig,omitempty"`
524+
}
525+
526+
// FileDiscoveryKubeConfig contains elements describing how to generate the kubeconfig for bootstrapping.
527+
type FileDiscoveryKubeConfig struct {
528+
// Cluster contains information about how to communicate with the kubernetes cluster.
529+
//
530+
// By default the following fields are automatically populated:
531+
// - Server with the Cluster's ControlPlaneEndpoint.
532+
// - CertificateAuthorityData with the Cluster's CA certificate.
533+
// +optional
534+
Cluster *KubeConfigCluster `json:"cluster,omitempty"`
535+
536+
// User contains information that describes identity information.
537+
// This is used to tell the kubernetes cluster who you are.
538+
User KubeConfigUser `json:"user"`
539+
}
540+
541+
// KubeConfigCluster contains information about how to communicate with a kubernetes cluster.
542+
//
543+
// Adapted from clientcmdv1.Cluster.
544+
type KubeConfigCluster struct {
545+
// Server is the address of the kubernetes cluster (https://hostname:port).
546+
//
547+
// Defaults to https:// + Cluster.Spec.ControlPlaneEndpoint.
548+
//
549+
// +optional
550+
Server string `json:"server,omitempty"`
551+
552+
// TLSServerName is used to check server certificate. If TLSServerName is empty, the hostname used to contact the server is used.
553+
// +optional
554+
TLSServerName string `json:"tlsServerName,omitempty"`
555+
556+
// InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
557+
// +optional
558+
InsecureSkipTLSVerify bool `json:"insecureSkipTLSVerify,omitempty"`
559+
560+
// CertificateAuthorityData contains PEM-encoded certificate authority certificates.
561+
//
562+
// Defaults to the Cluster's CA certificate if empty.
563+
//
564+
// +optional
565+
CertificateAuthorityData []byte `json:"certificateAuthorityData,omitempty"`
566+
567+
// ProxyURL is the URL to the proxy to be used for all requests made by this
568+
// client. URLs with "http", "https", and "socks5" schemes are supported. If
569+
// this configuration is not provided or the empty string, the client
570+
// attempts to construct a proxy configuration from http_proxy and
571+
// https_proxy environment variables. If these environment variables are not
572+
// set, the client does not attempt to proxy requests.
573+
//
574+
// socks5 proxying does not currently support spdy streaming endpoints (exec,
575+
// attach, port forward).
576+
//
577+
// +optional
578+
ProxyURL string `json:"proxyURL,omitempty"`
579+
}
580+
581+
// KubeConfigUser contains information that describes identity information.
582+
// This is used to tell the kubernetes cluster who you are.
583+
//
584+
// Either authProvider or exec must be filled.
585+
//
586+
// Adapted from clientcmdv1.AuthInfo.
587+
type KubeConfigUser struct {
588+
// AuthProvider specifies a custom authentication plugin for the kubernetes cluster.
589+
// +optional
590+
AuthProvider *KubeConfigAuthProvider `json:"authProvider,omitempty"`
591+
592+
// Exec specifies a custom exec-based authentication plugin for the kubernetes cluster.
593+
// +optional
594+
Exec *KubeConfigAuthExec `json:"exec,omitempty"`
595+
}
596+
597+
// KubeConfigAuthProvider holds the configuration for a specified auth provider.
598+
type KubeConfigAuthProvider struct {
599+
// Name is the name of the authentication plugin.
600+
Name string `json:"name"`
601+
602+
// Config holds the parameters for the authentication plugin.
603+
// +optional
604+
Config map[string]string `json:"config,omitempty"`
605+
}
606+
607+
// KubeConfigAuthExec specifies a command to provide client credentials. The command is exec'd
608+
// and outputs structured stdout holding credentials.
609+
//
610+
// See the client.authentication.k8s.io API group for specifications of the exact input
611+
// and output format.
612+
type KubeConfigAuthExec struct {
613+
// Command to execute.
614+
Command string `json:"command"`
615+
616+
// Arguments to pass to the command when executing it.
617+
// +optional
618+
Args []string `json:"args,omitempty"`
619+
620+
// Env defines additional environment variables to expose to the process. These
621+
// are unioned with the host's environment, as well as variables client-go uses
622+
// to pass argument to the plugin.
623+
// +optional
624+
Env []KubeConfigAuthExecEnv `json:"env,omitempty"`
625+
626+
// Preferred input version of the ExecInfo. The returned ExecCredentials MUST use
627+
// the same encoding version as the input.
628+
// Defaults to client.authentication.k8s.io/v1 if not set.
629+
// +optional
630+
APIVersion string `json:"apiVersion,omitempty"`
631+
632+
// ProvideClusterInfo determines whether or not to provide cluster information,
633+
// which could potentially contain very large CA data, to this exec plugin as a
634+
// part of the KUBERNETES_EXEC_INFO environment variable. By default, it is set
635+
// to false. Package k8s.io/client-go/tools/auth/exec provides helper methods for
636+
// reading this environment variable.
637+
// +optional
638+
ProvideClusterInfo bool `json:"provideClusterInfo,omitempty"`
639+
}
640+
641+
// KubeConfigAuthExecEnv is used for setting environment variables when executing an exec-based
642+
// credential plugin.
643+
type KubeConfigAuthExecEnv struct {
644+
Name string `json:"name"`
645+
Value string `json:"value"`
515646
}
516647

517648
// HostPathMount contains elements describing volumes that are mounted from the

bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go

+36
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ func (c *KubeadmConfigSpec) Default() {
132132
if c.JoinConfiguration != nil && c.JoinConfiguration.NodeRegistration.ImagePullPolicy == "" {
133133
c.JoinConfiguration.NodeRegistration.ImagePullPolicy = "IfNotPresent"
134134
}
135+
if c.JoinConfiguration != nil && c.JoinConfiguration.Discovery.File != nil {
136+
if kfg := c.JoinConfiguration.Discovery.File.KubeConfig; kfg != nil {
137+
if kfg.User.Exec != nil {
138+
if kfg.User.Exec.APIVersion == "" {
139+
kfg.User.Exec.APIVersion = "client.authentication.k8s.io/v1"
140+
}
141+
}
142+
}
143+
}
135144
}
136145

137146
// Validate ensures the KubeadmConfigSpec is valid.
@@ -142,6 +151,33 @@ func (c *KubeadmConfigSpec) Validate(pathPrefix *field.Path) field.ErrorList {
142151
allErrs = append(allErrs, c.validateUsers(pathPrefix)...)
143152
allErrs = append(allErrs, c.validateIgnition(pathPrefix)...)
144153

154+
// Validate JoinConfiguration.
155+
if c.JoinConfiguration != nil {
156+
if c.JoinConfiguration.Discovery.File != nil {
157+
if kfg := c.JoinConfiguration.Discovery.File.KubeConfig; kfg != nil {
158+
userPath := pathPrefix.Child("joinConfiguration", "discovery", "file", "kubeconfig", "user")
159+
if kfg.User.AuthProvider == nil && kfg.User.Exec == nil {
160+
allErrs = append(allErrs,
161+
field.Invalid(
162+
userPath,
163+
kfg.User,
164+
"at least one of authProvider or exec must be defined",
165+
),
166+
)
167+
}
168+
if kfg.User.AuthProvider != nil && kfg.User.Exec != nil {
169+
allErrs = append(allErrs,
170+
field.Invalid(
171+
userPath,
172+
kfg.User,
173+
"either authProvider or exec must be defined",
174+
),
175+
)
176+
}
177+
}
178+
}
179+
}
180+
145181
return allErrs
146182
}
147183

bootstrap/kubeadm/api/v1beta1/zz_generated.deepcopy.go

+134-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)