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

Automated cherry pick of #5976: Only genrate ETCD PKI for local ETCD setup #6008

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
12 changes: 6 additions & 6 deletions operator/pkg/certs/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ func (config *CertConfig) defaultNotAfter() {
}

// GetDefaultCertList returns all of karmada certConfigs, it include karmada, front and etcd.
func GetDefaultCertList() []*CertConfig {
return []*CertConfig{
func GetDefaultCertList(karmada *operatorv1alpha1.Karmada) []*CertConfig {
certConfigs := []*CertConfig{
// karmada cert config.
KarmadaCertRootCA(),
KarmadaCertAdmin(),
KarmadaCertApiserver(),
// front proxy cert config.
KarmadaCertFrontProxyCA(),
KarmadaCertFrontProxyClient(),
// ETCD cert config.
KarmadaCertEtcdCA(),
KarmadaCertEtcdServer(),
KarmadaCertEtcdClient(),
}
if karmada.Spec.Components.Etcd.Local != nil {
certConfigs = append(certConfigs, KarmadaCertEtcdCA(), KarmadaCertEtcdServer(), KarmadaCertEtcdClient())
}
return certConfigs
}

// KarmadaCertRootCA returns karmada ca cert config.
Expand Down
4 changes: 2 additions & 2 deletions operator/pkg/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func NewInitJob(opt *InitOptions) *workflow.Job {

// add the all tasks to the init job workflow.
initJob.AppendTask(tasks.NewPrepareCrdsTask())
initJob.AppendTask(tasks.NewCertTask())
initJob.AppendTask(tasks.NewCertTask(opt.Karmada))
initJob.AppendTask(tasks.NewNamespaceTask())
initJob.AppendTask(tasks.NewUploadCertsTask())
initJob.AppendTask(tasks.NewUploadCertsTask(opt.Karmada))

etcdConfig := opt.Karmada.Spec.Components.Etcd
// Only required if local etcd is configured
Expand Down
8 changes: 4 additions & 4 deletions operator/pkg/tasks/init/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
)

// NewCertTask init a Certs task to generate all of karmada certs
func NewCertTask() workflow.Task {
func NewCertTask(karmada *operatorv1alpha1.Karmada) workflow.Task {
return workflow.Task{
Name: "Certs",
Run: runCerts,
Skip: skipCerts,
RunSubTasks: true,
Tasks: newCertSubTasks(),
Tasks: newCertSubTasks(karmada),
}
}

Expand Down Expand Up @@ -74,11 +74,11 @@ func skipCerts(d workflow.RunData) (bool, error) {
return true, nil
}

func newCertSubTasks() []workflow.Task {
func newCertSubTasks(karmada *operatorv1alpha1.Karmada) []workflow.Task {
var subTasks []workflow.Task
caCert := map[string]*certs.CertConfig{}

for _, cert := range certs.GetDefaultCertList() {
for _, cert := range certs.GetDefaultCertList(karmada) {
var task workflow.Task

if cert.CAName == "" {
Expand Down
17 changes: 15 additions & 2 deletions operator/pkg/tasks/init/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ import (
fakeclientset "k8s.io/client-go/kubernetes/fake"

"github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
"github.com/karmada-io/karmada/operator/pkg/certs"
"github.com/karmada-io/karmada/operator/pkg/constants"
"github.com/karmada-io/karmada/operator/pkg/util"
"github.com/karmada-io/karmada/operator/pkg/workflow"
)

func TestNewCertTask(t *testing.T) {
karmada := &operatorv1alpha1.Karmada{
ObjectMeta: metav1.ObjectMeta{
Name: "karmada",
},
Spec: operatorv1alpha1.KarmadaSpec{
Components: &operatorv1alpha1.KarmadaComponents{
Etcd: &operatorv1alpha1.Etcd{
Local: &operatorv1alpha1.LocalEtcd{},
},
},
},
}
tests := []struct {
name string
wantTask workflow.Task
Expand All @@ -46,14 +59,14 @@ func TestNewCertTask(t *testing.T) {
Run: runCerts,
Skip: skipCerts,
RunSubTasks: true,
Tasks: newCertSubTasks(),
Tasks: newCertSubTasks(karmada),
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
certTask := NewCertTask()
certTask := NewCertTask(karmada)
err := util.DeepEqualTasks(certTask, test.wantTask)
if err != nil {
t.Errorf("unexpected error, got %v", err)
Expand Down
35 changes: 20 additions & 15 deletions operator/pkg/tasks/init/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/klog/v2"

operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
"github.com/karmada-io/karmada/operator/pkg/certs"
"github.com/karmada-io/karmada/operator/pkg/constants"
"github.com/karmada-io/karmada/operator/pkg/util"
Expand Down Expand Up @@ -179,25 +180,29 @@ func buildKubeConfigFromSpec(data InitData, serverURL string) (*clientcmdapi.Con
}

// NewUploadCertsTask init a Upload-Certs task
func NewUploadCertsTask() workflow.Task {
func NewUploadCertsTask(karmada *operatorv1alpha1.Karmada) workflow.Task {
tasks := []workflow.Task{
{
Name: "Upload-KarmadaCert",
Run: runUploadKarmadaCert,
},
{
Name: "Upload-WebHookCert",
Run: runUploadWebHookCert,
},
}
if karmada.Spec.Components.Etcd.Local != nil {
uploadEtcdTask := workflow.Task{
Name: "Upload-EtcdCert",
Run: runUploadEtcdCert,
}
tasks = append(tasks, uploadEtcdTask)
}
return workflow.Task{
Name: "Upload-Certs",
Run: runUploadCerts,
RunSubTasks: true,
Tasks: []workflow.Task{
{
Name: "Upload-KarmadaCert",
Run: runUploadKarmadaCert,
},
{
Name: "Upload-EtcdCert",
Run: runUploadEtcdCert,
},
{
Name: "Upload-WebHookCert",
Run: runUploadWebHookCert,
},
},
Tasks: tasks,
}
}

Expand Down