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

Ensure secret exists #56

Merged
merged 1 commit into from
Oct 19, 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
11 changes: 10 additions & 1 deletion pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ type PlatformConfig interface {
func launchProvisioningTask(r *ReconcileTaskRun, ctx context.Context, log *logr.Logger, tr *v1.TaskRun, secretName string, sshSecret string, address string, user string) error {
//kick off the provisioning task
//note that we can't use owner refs here because this task runs in a different namespace

//first verify the secret exists, so we don't hang if it is missing
secret := v12.Secret{}
err := r.client.Get(ctx, types.NamespacedName{Namespace: r.operatorNamespace, Name: sshSecret}, &secret)
if err != nil {
log.Error(fmt.Errorf("failed to find SSH secret %s", sshSecret), "failed to find SSH secret")
return r.createErrorSecret(ctx, tr, secretName, "failed to get SSH secret, system may not be configured correctly")
}

provision := v1.TaskRun{}
provision.GenerateName = "provision-task"
provision.Namespace = r.operatorNamespace
Expand Down Expand Up @@ -531,7 +540,7 @@ func launchProvisioningTask(r *ReconcileTaskRun, ctx context.Context, log *logr.
},
}

err := r.client.Create(ctx, &provision)
err = r.client.Create(ctx, &provision)
return err
}

Expand Down
20 changes: 14 additions & 6 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const userNamespace = "default"

var cloudImpl MockCloud = MockCloud{Addressses: map[cloud.InstanceIdentifier]string{}}

func setupClientAndReconciler(objs ...runtimeclient.Object) (runtimeclient.Client, *ReconcileTaskRun) {
func setupClientAndReconciler(objs []runtimeclient.Object) (runtimeclient.Client, *ReconcileTaskRun) {
scheme := runtime.NewScheme()
_ = pipelinev1.AddToScheme(scheme)
_ = v1.AddToScheme(scheme)
Expand Down Expand Up @@ -329,7 +329,7 @@ func runSuccessfulProvision(provision *pipelinev1.TaskRun, g *WithT, client runt

func TestNoHostConfig(t *testing.T) {
g := NewGomegaWithT(t)
client, reconciler := setupClientAndReconciler()
client, reconciler := setupClientAndReconciler([]runtimeclient.Object{})
createUserTaskRun(g, client, "test", "linux/arm64")
_, err := reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: userNamespace, Name: "test"}})
g.Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -414,7 +414,7 @@ func createUserTaskRun(g *WithT, client runtimeclient.Client, name string, platf
g.Expect(client.Create(context.TODO(), tr)).ToNot(HaveOccurred())
}

func createHostConfig() *v1.ConfigMap {
func createHostConfig() []runtimeclient.Object {
cm := v1.ConfigMap{}
cm.Name = HostConfig
cm.Namespace = systemNamespace
Expand All @@ -432,10 +432,14 @@ func createHostConfig() *v1.ConfigMap {
"host.host2.user": "ec2-user",
"host.host2.platform": "linux/arm64",
}
return &cm
sec := v1.Secret{}
sec.Name = "awskeys"
sec.Namespace = systemNamespace
sec.Labels = map[string]string{MultiPlatformSecretLabel: "true"}
return []runtimeclient.Object{&cm, &sec}
}

func createDynamicHostConfig() *v1.ConfigMap {
func createDynamicHostConfig() []runtimeclient.Object {
cm := v1.ConfigMap{}
cm.Name = HostConfig
cm.Namespace = systemNamespace
Expand All @@ -451,7 +455,11 @@ func createDynamicHostConfig() *v1.ConfigMap {
"dynamic.linux-arm64.ssh-secret": "awskeys",
"dynamic.linux-arm64.max-instances": "2",
}
return &cm
sec := v1.Secret{}
sec.Name = "awskeys"
sec.Namespace = systemNamespace
sec.Labels = map[string]string{MultiPlatformSecretLabel: "true"}
return []runtimeclient.Object{&cm, &sec}
}

type MockCloud struct {
Expand Down