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

Support structured config #575

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Refactoring StructuredConfig + controller's support to ConfigRefs tests
  • Loading branch information
ljtfreitas committed Apr 25, 2024
commit 79cadf2c8aa87d37a1d04f413913b5093e77b2e3
4 changes: 2 additions & 2 deletions deploy/crds/pulumi.com_stacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
which can be optionally specified inline. If this is omitted, configuration
is assumed to be checked in and taken from the source repository.
type: object
configsRef:
configRefs:
additionalProperties:
description: ConfigRef identifies a resource from which config information
can be loaded. Environment variables, files on the filesystem,
Expand Down Expand Up @@ -997,7 +997,7 @@ spec:
which can be optionally specified inline. If this is omitted, configuration
is assumed to be checked in and taken from the source repository.
type: object
configsRef:
configRefs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was suggested that we keep this limited to an alpha version like this before adding it to v1. That way we aren't immediately locked in to the API.

additionalProperties:
description: ConfigRef identifies a resource from which config information
can be loaded. Environment variables, files on the filesystem,
Expand Down
80 changes: 40 additions & 40 deletions docs/stacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ StackSpec defines the desired state of Pulumi Stack being managed by this operat
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkey">configsRef</a></b></td>
<td><b><a href="#stackspecconfigrefskey">configRefs</a></b></td>
<td>map[string]object</td>
<td>
(optional) ConfigRefs is the configuration for this stack, which can be specified through ConfigRef. is omitted, configuration is assumed to be checked in and taken from the source repository.<br/>
Expand Down Expand Up @@ -286,7 +286,7 @@ StackSpec defines the desired state of Pulumi Stack being managed by this operat
</table>


### Stack.spec.configsRef[key]
### Stack.spec.configRefs[key]
<sup><sup>[↩ Parent](#stackspec)</sup></sup>


Expand All @@ -310,42 +310,42 @@ ConfigRef identifies a resource from which config information can be loaded. Env
</td>
<td>true</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyconfigmap">configmap</a></b></td>
<td><b><a href="#stackspecconfigrefskeyconfigmap">configmap</a></b></td>
<td>object</td>
<td>
ConfigMapRef refers to a Kubernetes ConfigMap<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyenv">env</a></b></td>
<td><b><a href="#stackspecconfigrefskeyenv">env</a></b></td>
<td>object</td>
<td>
Env selects an environment variable set on the operator process<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyfilesystem">filesystem</a></b></td>
<td><b><a href="#stackspecconfigrefskeyfilesystem">filesystem</a></b></td>
<td>object</td>
<td>
FileSystem selects a file on the operator's file system<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyliteral">literal</a></b></td>
<td><b><a href="#stackspecconfigrefskeyliteral">literal</a></b></td>
<td>object</td>
<td>
LiteralRef refers to a literal value<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeysecret">secret</a></b></td>
<td><b><a href="#stackspecconfigrefskeysecret">secret</a></b></td>
<td>object</td>
<td>
SecretRef refers to a Kubernetes Secret<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeystructured">structured</a></b></td>
<td><b><a href="#stackspecconfigrefskeystructured">structured</a></b></td>
<td>object</td>
<td>
StructuredRef refers to a structured value<br/>
Expand All @@ -355,8 +355,8 @@ ConfigRef identifies a resource from which config information can be loaded. Env
</table>


### Stack.spec.configsRef[key].configmap
<sup><sup>[↩ Parent](#stackspecconfigsrefkey)</sup></sup>
### Stack.spec.configRefs[key].configmap
<sup><sup>[↩ Parent](#stackspecconfigrefskey)</sup></sup>



Expand Down Expand Up @@ -396,8 +396,8 @@ ConfigMapRef refers to a Kubernetes ConfigMap
</table>


### Stack.spec.configsRef[key].env
<sup><sup>[↩ Parent](#stackspecconfigsrefkey)</sup></sup>
### Stack.spec.configRefs[key].env
<sup><sup>[↩ Parent](#stackspecconfigrefskey)</sup></sup>



Expand All @@ -423,8 +423,8 @@ Env selects an environment variable set on the operator process
</table>


### Stack.spec.configsRef[key].filesystem
<sup><sup>[↩ Parent](#stackspecconfigsrefkey)</sup></sup>
### Stack.spec.configRefs[key].filesystem
<sup><sup>[↩ Parent](#stackspecconfigrefskey)</sup></sup>



Expand All @@ -450,8 +450,8 @@ FileSystem selects a file on the operator's file system
</table>


### Stack.spec.configsRef[key].literal
<sup><sup>[↩ Parent](#stackspecconfigsrefkey)</sup></sup>
### Stack.spec.configRefs[key].literal
<sup><sup>[↩ Parent](#stackspecconfigrefskey)</sup></sup>



Expand All @@ -477,8 +477,8 @@ LiteralRef refers to a literal value
</table>


### Stack.spec.configsRef[key].secret
<sup><sup>[↩ Parent](#stackspecconfigsrefkey)</sup></sup>
### Stack.spec.configRefs[key].secret
<sup><sup>[↩ Parent](#stackspecconfigrefskey)</sup></sup>



Expand Down Expand Up @@ -518,8 +518,8 @@ SecretRef refers to a Kubernetes Secret
</table>


### Stack.spec.configsRef[key].structured
<sup><sup>[↩ Parent](#stackspecconfigsrefkey)</sup></sup>
### Stack.spec.configRefs[key].structured
<sup><sup>[↩ Parent](#stackspecconfigrefskey)</sup></sup>



Expand Down Expand Up @@ -2361,7 +2361,7 @@ StackSpec defines the desired state of Pulumi Stack being managed by this operat
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkey-1">configsRef</a></b></td>
<td><b><a href="#stackspecconfigrefskey-1">configRefs</a></b></td>
<td>map[string]object</td>
<td>
(optional) ConfigRefs is the configuration for this stack, which can be specified through ConfigRef. is omitted, configuration is assumed to be checked in and taken from the source repository.<br/>
Expand Down Expand Up @@ -2520,7 +2520,7 @@ StackSpec defines the desired state of Pulumi Stack being managed by this operat
</table>


### Stack.spec.configsRef[key]
### Stack.spec.configRefs[key]
<sup><sup>[↩ Parent](#stackspec-1)</sup></sup>


Expand All @@ -2544,42 +2544,42 @@ ConfigRef identifies a resource from which config information can be loaded. Env
</td>
<td>true</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyconfigmap-1">configmap</a></b></td>
<td><b><a href="#stackspecconfigrefskeyconfigmap-1">configmap</a></b></td>
<td>object</td>
<td>
ConfigMapRef refers to a Kubernetes ConfigMap<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyenv-1">env</a></b></td>
<td><b><a href="#stackspecconfigrefskeyenv-1">env</a></b></td>
<td>object</td>
<td>
Env selects an environment variable set on the operator process<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyfilesystem-1">filesystem</a></b></td>
<td><b><a href="#stackspecconfigrefskeyfilesystem-1">filesystem</a></b></td>
<td>object</td>
<td>
FileSystem selects a file on the operator's file system<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeyliteral-1">literal</a></b></td>
<td><b><a href="#stackspecconfigrefskeyliteral-1">literal</a></b></td>
<td>object</td>
<td>
LiteralRef refers to a literal value<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeysecret-1">secret</a></b></td>
<td><b><a href="#stackspecconfigrefskeysecret-1">secret</a></b></td>
<td>object</td>
<td>
SecretRef refers to a Kubernetes Secret<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#stackspecconfigsrefkeystructured-1">structured</a></b></td>
<td><b><a href="#stackspecconfigrefskeystructured-1">structured</a></b></td>
<td>object</td>
<td>
StructuredRef refers to a structured value<br/>
Expand All @@ -2589,8 +2589,8 @@ ConfigRef identifies a resource from which config information can be loaded. Env
</table>


### Stack.spec.configsRef[key].configmap
<sup><sup>[↩ Parent](#stackspecconfigsrefkey-1)</sup></sup>
### Stack.spec.configRefs[key].configmap
<sup><sup>[↩ Parent](#stackspecconfigrefskey-1)</sup></sup>



Expand Down Expand Up @@ -2630,8 +2630,8 @@ ConfigMapRef refers to a Kubernetes ConfigMap
</table>


### Stack.spec.configsRef[key].env
<sup><sup>[↩ Parent](#stackspecconfigsrefkey-1)</sup></sup>
### Stack.spec.configRefs[key].env
<sup><sup>[↩ Parent](#stackspecconfigrefskey-1)</sup></sup>



Expand All @@ -2657,8 +2657,8 @@ Env selects an environment variable set on the operator process
</table>


### Stack.spec.configsRef[key].filesystem
<sup><sup>[↩ Parent](#stackspecconfigsrefkey-1)</sup></sup>
### Stack.spec.configRefs[key].filesystem
<sup><sup>[↩ Parent](#stackspecconfigrefskey-1)</sup></sup>



Expand All @@ -2684,8 +2684,8 @@ FileSystem selects a file on the operator's file system
</table>


### Stack.spec.configsRef[key].literal
<sup><sup>[↩ Parent](#stackspecconfigsrefkey-1)</sup></sup>
### Stack.spec.configRefs[key].literal
<sup><sup>[↩ Parent](#stackspecconfigrefskey-1)</sup></sup>



Expand All @@ -2711,8 +2711,8 @@ LiteralRef refers to a literal value
</table>


### Stack.spec.configsRef[key].secret
<sup><sup>[↩ Parent](#stackspecconfigsrefkey-1)</sup></sup>
### Stack.spec.configRefs[key].secret
<sup><sup>[↩ Parent](#stackspecconfigrefskey-1)</sup></sup>



Expand Down Expand Up @@ -2752,8 +2752,8 @@ SecretRef refers to a Kubernetes Secret
</table>


### Stack.spec.configsRef[key].structured
<sup><sup>[↩ Parent](#stackspecconfigsrefkey-1)</sup></sup>
### Stack.spec.configRefs[key].structured
<sup><sup>[↩ Parent](#stackspecconfigrefskey-1)</sup></sup>



Expand Down
62 changes: 60 additions & 2 deletions pkg/apis/pulumi/shared/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type StackSpec struct {
Config map[string]string `json:"config,omitempty"`
// (optional) ConfigRefs is the configuration for this stack, which can be specified through ConfigRef.
// is omitted, configuration is assumed to be checked in and taken from the source repository.
ConfigRefs map[string]ConfigRef `json:"configsRef,omitempty"`
ConfigRefs map[string]ConfigRef `json:"configRefs,omitempty"`
// (optional) Secrets is the secret configuration for this stack, which can be optionally specified inline. If this
// is omitted, secrets configuration is assumed to be checked in and taken from the source repository.
// Deprecated: use SecretRefs instead.
Expand Down Expand Up @@ -275,6 +275,16 @@ func NewEnvResourceRef(envVarName string) ResourceRef {
}
}

func NewEnvConfigResourceRef(envVarName string) ConfigRef {
envResourceRef := NewEnvResourceRef(envVarName)
return ConfigRef{
SelectorType: ConfigResourceSelectorType(envResourceRef.SelectorType),
ConfigResourceSelector: ConfigResourceSelector{
ResourceSelector: envResourceRef.ResourceSelector,
},
}
}

// NewFileSystemResourceRef creates a new file system resource ref.
func NewFileSystemResourceRef(path string) ResourceRef {
return ResourceRef{
Expand All @@ -287,6 +297,17 @@ func NewFileSystemResourceRef(path string) ResourceRef {
}
}

// NewConfigFileSystemResourceRef creates a new file system resource ref.
func NewFileSystemConfigResourceRef(path string) ConfigRef {
fsResourceRef := NewFileSystemResourceRef(path)
return ConfigRef{
SelectorType: ConfigResourceSelectorType(fsResourceRef.SelectorType),
ConfigResourceSelector: ConfigResourceSelector{
ResourceSelector: fsResourceRef.ResourceSelector,
},
}
}

// NewSecretResourceRef creates a new Secret resource ref.
func NewSecretResourceRef(namespace, name, key string) ResourceRef {
return ResourceRef{
Expand All @@ -301,7 +322,7 @@ func NewSecretResourceRef(namespace, name, key string) ResourceRef {
}
}

// NewSecretResourceRef creates a new Secret resource ref.
// NewSecretConfigResourceRef creates a new Secret resource ref to be used as config.
func NewSecretConfigResourceRef(namespace, name, key string) ConfigRef {
secretResourceRef := NewSecretResourceRef(namespace, name, key)
return ConfigRef{
Expand All @@ -324,6 +345,43 @@ func NewLiteralResourceRef(value string) ResourceRef {
}
}

// NewLiteralConfigResourceRef creates a new config literal resource ref.
func NewLiteralConfigResourceRef(value string) ConfigRef {
literalResourceRef := NewLiteralResourceRef(value)
return ConfigRef{
SelectorType: ConfigResourceSelectorType(literalResourceRef.SelectorType),
ConfigResourceSelector: ConfigResourceSelector{
ResourceSelector: literalResourceRef.ResourceSelector,
},
}
}

// NewStructuredConfigResourceRef creates a new structured config resource ref.
func NewStructuredConfigResourceRef(config apiextensionsv1.JSON) ConfigRef {
return ConfigRef{
SelectorType: ConfigResourceSelectorStructured,
ConfigResourceSelector: ConfigResourceSelector{
StructuredRef: &StructuredRef{
Value: config,
},
},
}
}

// NewConfigMapConfigResourceRef creates a new ConfigMap resource ref to be used as config.
func NewConfigMapConfigResourceRef(namespace, name, key string) ConfigRef {
return ConfigRef{
SelectorType: ConfigResourceSelectorConfigMap,
ConfigResourceSelector: ConfigResourceSelector{
ConfigMapRef: &ConfigMapSelector{
Namespace: namespace,
Name: name,
Key: key,
},
},
}
}

// ResourceSelectorType identifies the type of the resource reference in
type ResourceSelectorType string

Expand Down
Loading
Loading