Skip to content

Commit

Permalink
feat: extend stack attributes for files and secret files (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored May 10, 2024
1 parent 3568dab commit 1ec98fa
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,22 @@ spec:
type: object
type: array
files:
description: Files reference to ConfigMap with a key as a path and
description: Files reference to ConfigMaps with a key as a path and
value as a content
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
git:
description: Git reference w/in the repository where the IaC lives
properties:
Expand Down Expand Up @@ -8159,6 +8164,23 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
secretFiles:
description: SecretFiles reference to Secrets with a key as a path
and value as a content
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
type:
description: Type specifies the tool to use to apply it
enum:
Expand Down
7 changes: 5 additions & 2 deletions controller/api/v1alpha1/infrastructurestack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ type InfrastructureStackSpec struct {
// +kubebuilder:validation:Optional
Environment []StackEnvironment `json:"environment,omitempty"`

// Files reference to ConfigMap with a key as a path and value as a content
// Files reference to ConfigMaps with a key as a path and value as a content
// +kubebuilder:validation:Optional
Files *corev1.LocalObjectReference `json:"files,omitempty"`
Files []corev1.LocalObjectReference `json:"files,omitempty"`
// SecretFiles reference to Secrets with a key as a path and value as a content
// +kubebuilder:validation:Optional
SecretFiles []corev1.LocalObjectReference `json:"secretFiles,omitempty"`

// Detach determined if user want to delete or detach stack
Detach bool `json:"detach"`
Expand Down
9 changes: 7 additions & 2 deletions controller/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,22 @@ spec:
type: object
type: array
files:
description: Files reference to ConfigMap with a key as a path and
description: Files reference to ConfigMaps with a key as a path and
value as a content
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
git:
description: Git reference w/in the repository where the IaC lives
properties:
Expand Down Expand Up @@ -8159,6 +8164,23 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
secretFiles:
description: SecretFiles reference to Secrets with a key as a path
and value as a content
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
type:
description: Type specifies the tool to use to apply it
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ spec:
ref: main
folder: terraform
files:
name: infrastructurestack
- name: infrastructurestack
environment:
- name: test
value: test
Expand Down
18 changes: 15 additions & 3 deletions controller/internal/controller/infrastructurestack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ func (r *InfrastructureStackReconciler) getStackAttributes(ctx context.Context,
Files: make([]*console.StackFileAttributes, 0),
}

if stack.Spec.Files != nil {
for _, file := range stack.Spec.Files {
configMap := &corev1.ConfigMap{}
name := types.NamespacedName{Name: stack.Spec.Files.Name, Namespace: stack.GetNamespace()}
name := types.NamespacedName{Name: file.Name, Namespace: stack.GetNamespace()}
if err := r.Get(ctx, name, configMap); err != nil {
return nil, err
}
Expand All @@ -243,7 +243,19 @@ func (r *InfrastructureStackReconciler) getStackAttributes(ctx context.Context,
Content: v,
})
}

}
for _, file := range stack.Spec.SecretFiles {
secret := &corev1.Secret{}
name := types.NamespacedName{Name: file.Name, Namespace: stack.GetNamespace()}
if err := r.Get(ctx, name, secret); err != nil {
return nil, err
}
for k, v := range secret.Data {
attr.Files = append(attr.Files, &console.StackFileAttributes{
Path: k,
Content: string(v),
})
}
}

attr.Environment = algorithms.Map(stack.Spec.Environment,
Expand Down
2 changes: 1 addition & 1 deletion controller/internal/test/mocks/ConsoleClient_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,22 @@ spec:
type: object
type: array
files:
description: Files reference to ConfigMap with a key as a path and
description: Files reference to ConfigMaps with a key as a path and
value as a content
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
git:
description: Git reference w/in the repository where the IaC lives
properties:
Expand Down Expand Up @@ -8159,6 +8164,23 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
secretFiles:
description: SecretFiles reference to Secrets with a key as a path
and value as a content
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
type:
description: Type specifies the tool to use to apply it
enum:
Expand Down

0 comments on commit 1ec98fa

Please sign in to comment.