Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy etcd CA cert if k3s use embeded etcd #78

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bootstrap/api/v1beta1/kthreesconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type KThreesConfigSpec struct {
Version string `json:"version,omitempty"`
}

// TODO
// Will need extend this func when implementing other k3s database options.
func (c *KThreesConfigSpec) IsEtcdEmbedded() bool {
return true
}

type KThreesServerConfig struct {
// KubeAPIServerArgs is a customized flag for kube-apiserver process
// +optional
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/controllers/kthreesconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (r *KThreesConfigReconciler) handleClusterNotInitialized(ctx context.Contex
// injects into config.ClusterConfiguration values from top level object
r.reconcileTopLevelObjectSettings(scope.Cluster, machine, scope.Config)

certificates := secret.NewCertificatesForInitialControlPlane()
certificates := secret.NewCertificatesForInitialControlPlane(&scope.Config.Spec)
err := certificates.LookupOrGenerate(
ctx,
r.Client,
Expand Down
2 changes: 1 addition & 1 deletion controlplane/controllers/kthreescontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (r *KThreesControlPlaneReconciler) reconcile(ctx context.Context, cluster *
return reconcile.Result{}, err
}

certificates := secret.NewCertificatesForInitialControlPlane()
certificates := secret.NewCertificatesForInitialControlPlane(&kcp.Spec.KThreesConfigSpec)
controllerRef := metav1.NewControllerRef(kcp, controlplanev1.GroupVersion.WithKind("KThreesControlPlane"))
if err := certificates.LookupOrGenerate(ctx, r.Client, util.ObjectKey(cluster), *controllerRef); err != nil {
logger.Error(err, "unable to lookup or create cluster certificates")
Expand Down
11 changes: 10 additions & 1 deletion pkg/secret/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
type Certificates []*Certificate

// NewCertificatesForInitialControlPlane returns a list of certificates configured for a control plane node.
func NewCertificatesForInitialControlPlane() Certificates {
func NewCertificatesForInitialControlPlane(config *bootstrapv1.KThreesConfigSpec) Certificates {
zawachte marked this conversation as resolved.
Show resolved Hide resolved
certificatesDir := DefaultCertificatesDir

certificates := Certificates{
Expand All @@ -81,6 +81,15 @@ func NewCertificatesForInitialControlPlane() Certificates {
},
}

if config.IsEtcdEmbedded() {
etcdCert := &Certificate{
Purpose: EtcdCA,
CertFile: filepath.Join(certificatesDir, "etcd", "server-ca.crt"),
KeyFile: filepath.Join(certificatesDir, "etcd", "server-ca.key"),
}
certificates = append(certificates, etcdCert)
}

return certificates
}

Expand Down
Loading