Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Adding support for output annotations #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions api/v1alpha1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type WorkspaceSpec struct {
// Specifies the agent pool name we wish to use.
// +optional
AgentPoolName string `json:"agentPoolName,omitempty"`
// Annotations for the output secret.
// +optional
OutputAnnotations map[string]string `json:"outputAnnotations,omitempty"`
}

// WorkspaceStatus defines the observed state of Workspace
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/app.terraform.io_workspaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ spec:
organization:
description: Terraform Cloud organization
type: string
outputAnnotations:
additionalProperties:
type: string
description: Annotations for the output secret.
type: object
outputs:
description: Outputs denote outputs wanted
items:
Expand Down
9 changes: 5 additions & 4 deletions workspacehelper/k8s_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ func configMapForTerraform(name string, namespace string, template []byte) *core
}
}

func secretForOutputs(name string, namespace string, outputs []*v1alpha1.OutputStatus) *corev1.Secret {
func secretForOutputs(name string, namespace string, outputs []*v1alpha1.OutputStatus, annotations map[string]string) *corev1.Secret {
data := outputsToMap(outputs)
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Name: name,
Namespace: namespace,
Annotations: annotations,
},
Data: data,
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func (r *WorkspaceHelper) UpsertSecretOutputs(w *v1alpha1.Workspace, outputs []*
outputName := fmt.Sprintf("%s-outputs", w.Name)
err := r.client.Get(context.TODO(), types.NamespacedName{Name: outputName, Namespace: w.Namespace}, found)
if err != nil && k8serrors.IsNotFound(err) {
secret := secretForOutputs(outputName, w.Namespace, outputs)
secret := secretForOutputs(outputName, w.Namespace, outputs, w.Spec.OutputAnnotations)
err = controllerutil.SetControllerReference(w, secret, r.scheme)
if err != nil {
return err
Expand Down