mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Make the replica transformer kind aware.
The previous implementation had a bug and poorly handled types that should not have a `spec: replica:` field. Documentation is updated to reflect the change in behavior, and better highlights the cases where a patch should be used instead of this shorthand.
This commit is contained in:
@@ -32,6 +32,7 @@ func GetDefaultFieldSpecs() []byte {
|
||||
[]byte(varReferenceFieldSpecs),
|
||||
[]byte(nameReferenceFieldSpecs),
|
||||
[]byte(imagesFieldSpecs),
|
||||
[]byte(replicasFieldSpecs),
|
||||
}
|
||||
return bytes.Join(configData, []byte("\n"))
|
||||
}
|
||||
@@ -47,5 +48,6 @@ func GetDefaultFieldSpecsAsMap() map[string]string {
|
||||
result["varreference"] = varReferenceFieldSpecs
|
||||
result["namereference"] = nameReferenceFieldSpecs
|
||||
result["images"] = imagesFieldSpecs
|
||||
result["replicas"] = replicasFieldSpecs
|
||||
return result
|
||||
}
|
||||
|
||||
20
pkg/transformers/config/defaultconfig/replicas.go
Normal file
20
pkg/transformers/config/defaultconfig/replicas.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package defaultconfig
|
||||
|
||||
const replicasFieldSpecs = `
|
||||
replicas:
|
||||
- path: spec/replicas
|
||||
create: true
|
||||
kind: Deployment
|
||||
|
||||
- path: spec/replicas
|
||||
create: true
|
||||
kind: ReplicationController
|
||||
|
||||
- path: spec/replicas
|
||||
create: true
|
||||
kind: ReplicaSet
|
||||
|
||||
- path: spec/replicas
|
||||
create: true
|
||||
kind: StatefulSet
|
||||
`
|
||||
@@ -35,6 +35,7 @@ type TransformerConfig struct {
|
||||
NameReference nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
|
||||
VarReference fsSlice `json:"varReference,omitempty" yaml:"varReference,omitempty"`
|
||||
Images fsSlice `json:"images,omitempty" yaml:"images,omitempty"`
|
||||
Replicas fsSlice `json:"replicas,omitempty" yaml:"replicas,omitempty"`
|
||||
}
|
||||
|
||||
// MakeEmptyConfig returns an empty TransformerConfig object
|
||||
@@ -61,6 +62,7 @@ func (t *TransformerConfig) sortFields() {
|
||||
sort.Sort(t.NameReference)
|
||||
sort.Sort(t.VarReference)
|
||||
sort.Sort(t.Images)
|
||||
sort.Sort(t.Replicas)
|
||||
}
|
||||
|
||||
// AddPrefixFieldSpec adds a FieldSpec to NamePrefix
|
||||
@@ -135,6 +137,10 @@ func (t *TransformerConfig) Merge(input *TransformerConfig) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
merged.Replicas, err = t.Replicas.mergeAll(input.Replicas)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
merged.sortFields()
|
||||
return merged, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user