Skip to content

Commit

Permalink
add EnvFrom-like VarsFrom secrets and configmaps
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
abursavich committed Aug 28, 2020
1 parent 755ba30 commit 3adf07a
Show file tree
Hide file tree
Showing 8 changed files with 762 additions and 74 deletions.
38 changes: 37 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
* [ConfigMapSecretSpec](#configmapsecretspec)
* [ConfigMapSecretStatus](#configmapsecretstatus)
* [ConfigMapTemplate](#configmaptemplate)
* [ConfigMapVarsSource](#configmapvarssource)
* [SecretVarsSource](#secretvarssource)
* [TemplateMetadata](#templatemetadata)
* [TemplateVariable](#templatevariable)
* [VarsFromSource](#varsfromsource)

## ConfigMapSecret

Expand Down Expand Up @@ -67,6 +70,7 @@ ConfigMapSecretSpec defines the desired state of a ConfigMapSecret.
| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| template | Template that describes the config that will be rendered.<br/><br/>Variable references $(VAR_NAME) in template data are expanded using the ConfigMapSecret's variables. If a variable cannot be resolved, the reference in the input data will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. | [ConfigMapTemplate](#configmaptemplate) | false |
| varsFrom | List of sources to populate template variables. Keys defined in a source must consist of alphanumeric characters, '-', '_' or '.'. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by Vars with a duplicate key will take precedence. | [][VarsFromSource](#varsfromsource) | false |
| vars | List of template variables. | [][TemplateVariable](#templatevariable) | false |

[Back to TOC](#table-of-contents)
Expand Down Expand Up @@ -94,6 +98,26 @@ ConfigMapTemplate is a ConfigMap template.

[Back to TOC](#table-of-contents)

## ConfigMapVarsSource

ConfigMapVarsSource selects a ConfigMap to populate template variables with.

| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| optional | Specify whether the ConfigMap must be defined. | *bool | false |

[Back to TOC](#table-of-contents)

## SecretVarsSource

SecretVarsSource selects a Secret to populate template variables with.

| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| optional | Specify whether the Secret must be defined. | *bool | false |

[Back to TOC](#table-of-contents)

## TemplateMetadata

TemplateMetadata is a stripped down version of the standard object metadata.
Expand All @@ -113,8 +137,20 @@ TemplateVariable is a template variable.
| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| name | Name of the template variable. | string | true |
| value | Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the ConfigMapSecret. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not.<br/><br/>Defaults to \"\". | string | false |
| value | Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the ConfigMapSecret. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. | string | false |
| secretValue | SecretValue selects a value by its key in a Secret. | *[corev1.SecretKeySelector](https://pkg.go.dev/k8s.io/api/core/v1#SecretKeySelector) | false |
| configMapValue | ConfigMapValue selects a value by its key in a ConfigMap. | *[corev1.ConfigMapKeySelector](https://pkg.go.dev/k8s.io/api/core/v1#ConfigMapKeySelector) | false |

[Back to TOC](#table-of-contents)

## VarsFromSource

VarsFromSource represents the source of a set of template variables.

| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| prefix | An optional identifier to prepend to each key. | string | false |
| secretRef | The Secret to select. | *[SecretVarsSource](#secretvarssource) | false |
| configMapRef | The ConfigMap to select. | *[ConfigMapVarsSource](#configmapvarssource) | false |

[Back to TOC](#table-of-contents)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Azure/go-autorest/autorest v0.11.4 // indirect
github.com/go-logr/logr v0.2.1-0.20200730175230-ee2de8da5be6
github.com/go-logr/zapr v0.2.0
github.com/google/go-cmp v0.5.2 // indirect
github.com/google/go-cmp v0.5.2
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.1 // indirect
github.com/imdario/mergo v0.3.11 // indirect
Expand Down
32 changes: 31 additions & 1 deletion manifest/customresourcedefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,42 @@ spec:
- key
type: object
value:
description: "Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the ConfigMapSecret. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. \n Defaults to \"\"."
description: 'Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the ConfigMapSecret. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not.'
type: string
required:
- name
type: object
type: array
varsFrom:
description: List of sources to populate template variables. Keys defined in a source must consist of alphanumeric characters, '-', '_' or '.'. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by Vars with a duplicate key will take precedence.
items:
description: VarsFromSource represents the source of a set of template variables.
properties:
configMapRef:
description: The ConfigMap to select.
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
optional:
description: Specify whether the ConfigMap must be defined.
type: boolean
type: object
prefix:
description: An optional identifier to prepend to each key.
type: string
secretRef:
description: The Secret to select.
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
optional:
description: Specify whether the Secret must be defined.
type: boolean
type: object
type: object
type: array
type: object
status:
description: 'Observed state of the ConfigMapSecret. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status'
Expand Down
39 changes: 37 additions & 2 deletions pkg/api/v1alpha1/configmapsecret_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ type ConfigMapSecretSpec struct {
// regardless of whether the variable exists or not.
Template ConfigMapTemplate `json:"template,omitempty"`

// List of sources to populate template variables.
// Keys defined in a source must consist of alphanumeric characters, '-', '_' or '.'.
// When a key exists in multiple sources, the value associated with the last
// source will take precedence. Values defined by Vars with a duplicate key
// will take precedence.
VarsFrom []VarsFromSource `json:"varsFrom,omitempty"`

// List of template variables.
Vars []TemplateVariable `json:"vars,omitempty"`
}
Expand Down Expand Up @@ -116,8 +123,6 @@ type TemplateVariable struct {
// the reference in the input string will be unchanged. The $(VAR_NAME) syntax
// can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will
// never be expanded, regardless of whether the variable exists or not.
//
// Defaults to "".
Value string `json:"value,omitempty"`

// SecretValue selects a value by its key in a Secret.
Expand All @@ -127,6 +132,36 @@ type TemplateVariable struct {
ConfigMapValue *corev1.ConfigMapKeySelector `json:"configMapValue,omitempty"`
}

// VarsFromSource represents the source of a set of template variables.
type VarsFromSource struct {
// An optional identifier to prepend to each key.
Prefix string `json:"prefix,omitempty"`

// The Secret to select.
SecretRef *SecretVarsSource `json:"secretRef,omitempty"`

// The ConfigMap to select.
ConfigMapRef *ConfigMapVarsSource `json:"configMapRef,omitempty"`
}

// SecretVarsSource selects a Secret to populate template variables with.
type SecretVarsSource struct {
// The Secret to select.
corev1.LocalObjectReference `json:",inline"`

// Specify whether the Secret must be defined.
Optional *bool `json:"optional,omitempty"`
}

// ConfigMapVarsSource selects a ConfigMap to populate template variables with.
type ConfigMapVarsSource struct {
// The ConfigMap to select.
corev1.LocalObjectReference `json:",inline"`

// Specify whether the ConfigMap must be defined.
Optional *bool `json:"optional,omitempty"`
}

// ConfigMapSecretStatus describes the observed state of a ConfigMapSecret.
type ConfigMapSecretStatus struct {
// The generation observed by the ConfigMapSecret controller.
Expand Down
74 changes: 74 additions & 0 deletions pkg/api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 3adf07a

Please sign in to comment.