Merge pull request #3795 from jlandowner/master

Support immutable attribute on generators
This commit is contained in:
Kubernetes Prow Robot
2021-04-15 22:36:22 -07:00
committed by GitHub
7 changed files with 37 additions and 0 deletions

View File

@@ -15,6 +15,9 @@ type GeneratorOptions struct {
// suffix to the names of generated resources that is a hash of the
// resource contents.
DisableNameSuffixHash bool `json:"disableNameSuffixHash,omitempty" yaml:"disableNameSuffixHash,omitempty"`
// Immutable if true add to all generated resources.
Immutable bool `json:"immutable,omitempty" yaml:"immutable,omitempty"`
}
// MergeGlobalOptionsIntoLocal merges two instances of GeneratorOptions.
@@ -42,6 +45,9 @@ func MergeGlobalOptionsIntoLocal(
if globalOpts.DisableNameSuffixHash {
localOpts.DisableNameSuffixHash = true
}
if globalOpts.Immutable {
localOpts.Immutable = true
}
return localOpts
}

View File

@@ -34,6 +34,7 @@ func TestMergeGlobalOptionsIntoLocal(t *testing.T) {
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{"fruit": "apple"},
DisableNameSuffixHash: false,
Immutable: false,
},
},
{
@@ -47,6 +48,7 @@ func TestMergeGlobalOptionsIntoLocal(t *testing.T) {
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{"fruit": "apple"},
DisableNameSuffixHash: false,
Immutable: false,
},
},
{
@@ -76,42 +78,52 @@ func TestMergeGlobalOptionsIntoLocal(t *testing.T) {
"tesla": "Y",
},
DisableNameSuffixHash: false,
Immutable: false,
},
},
{
name: "global disable trumps local",
local: &GeneratorOptions{
DisableNameSuffixHash: false,
Immutable: false,
},
global: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
expected: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
},
{
name: "local disable works",
local: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
global: &GeneratorOptions{
DisableNameSuffixHash: false,
Immutable: false,
},
expected: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
},
{
name: "everyone wants disable",
local: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
global: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
expected: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
},
}