Skip to content

Commit

Permalink
Merge pull request #56 from stuartwdouglas/error-handling
Browse files Browse the repository at this point in the history
Ensure secret exists
  • Loading branch information
stuartwdouglas authored Oct 19, 2023
2 parents d919bd3 + 1da9999 commit f311350
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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

0 comments on commit f311350

Please sign in to comment.