Remove deprecated `patchesStrategicMerge` and `patchesJson6902` from v2 API
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
dfee7b086d
commit
42fe4a39c1
|
|
@ -76,23 +76,7 @@ const (
|
|||
// HelmRelease failed.
|
||||
ArtifactFailedReason string = "ArtifactFailed"
|
||||
|
||||
// InitFailedReason represents the fact that the initialization of the Helm
|
||||
// configuration failed.
|
||||
InitFailedReason string = "InitFailed"
|
||||
|
||||
// GetLastReleaseFailedReason represents the fact that observing the last
|
||||
// release failed.
|
||||
GetLastReleaseFailedReason string = "GetLastReleaseFailed"
|
||||
|
||||
// DependencyNotReadyReason represents the fact that
|
||||
// one of the dependencies is not ready.
|
||||
DependencyNotReadyReason string = "DependencyNotReady"
|
||||
|
||||
// ReconciliationSucceededReason represents the fact that
|
||||
// the reconciliation succeeded.
|
||||
ReconciliationSucceededReason string = "ReconciliationSucceeded"
|
||||
|
||||
// ReconciliationFailedReason represents the fact that
|
||||
// the reconciliation failed.
|
||||
ReconciliationFailedReason string = "ReconciliationFailed"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -49,16 +49,6 @@ type Kustomize struct {
|
|||
// +optional
|
||||
Patches []kustomize.Patch `json:"patches,omitempty"`
|
||||
|
||||
// Strategic merge patches, defined as inline YAML objects.
|
||||
// Deprecated: use Patches instead.
|
||||
// +optional
|
||||
PatchesStrategicMerge []apiextensionsv1.JSON `json:"patchesStrategicMerge,omitempty"`
|
||||
|
||||
// JSON 6902 patches, defined as inline YAML objects.
|
||||
// Deprecated: use Patches instead.
|
||||
// +optional
|
||||
PatchesJSON6902 []kustomize.JSON6902Patch `json:"patchesJson6902,omitempty"`
|
||||
|
||||
// Images is a list of (image name, new name, new tag or digest)
|
||||
// for changing image names, tags or digests. This can also be achieved with a
|
||||
// patch, but this operator is simpler to specify.
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ package v2
|
|||
import (
|
||||
"github.com/fluxcd/pkg/apis/kustomize"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ func (in *HelmChartTemplateSpec) DeepCopyInto(out *HelmChartTemplateSpec) {
|
|||
out.SourceRef = in.SourceRef
|
||||
if in.Interval != nil {
|
||||
in, out := &in.Interval, &out.Interval
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
if in.ValuesFiles != nil {
|
||||
|
|
@ -277,7 +277,7 @@ func (in *HelmReleaseSpec) DeepCopyInto(out *HelmReleaseSpec) {
|
|||
}
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
if in.MaxHistory != nil {
|
||||
|
|
@ -327,7 +327,7 @@ func (in *HelmReleaseSpec) DeepCopyInto(out *HelmReleaseSpec) {
|
|||
}
|
||||
if in.Values != nil {
|
||||
in, out := &in.Values, &out.Values
|
||||
*out = new(v1.JSON)
|
||||
*out = new(apiextensionsv1.JSON)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.PostRenderers != nil {
|
||||
|
|
@ -354,7 +354,7 @@ func (in *HelmReleaseStatus) DeepCopyInto(out *HelmReleaseStatus) {
|
|||
*out = *in
|
||||
if in.Conditions != nil {
|
||||
in, out := &in.Conditions, &out.Conditions
|
||||
*out = make([]metav1.Condition, len(*in))
|
||||
*out = make([]v1.Condition, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
|
|
@ -413,7 +413,7 @@ func (in *Install) DeepCopyInto(out *Install) {
|
|||
*out = *in
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
if in.Remediation != nil {
|
||||
|
|
@ -468,20 +468,6 @@ func (in *Kustomize) DeepCopyInto(out *Kustomize) {
|
|||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.PatchesStrategicMerge != nil {
|
||||
in, out := &in.PatchesStrategicMerge, &out.PatchesStrategicMerge
|
||||
*out = make([]v1.JSON, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.PatchesJSON6902 != nil {
|
||||
in, out := &in.PatchesJSON6902, &out.PatchesJSON6902
|
||||
*out = make([]kustomize.JSON6902Patch, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.Images != nil {
|
||||
in, out := &in.Images, &out.Images
|
||||
*out = make([]kustomize.Image, len(*in))
|
||||
|
|
@ -524,7 +510,7 @@ func (in *Rollback) DeepCopyInto(out *Rollback) {
|
|||
*out = *in
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
|
@ -607,7 +593,7 @@ func (in *Test) DeepCopyInto(out *Test) {
|
|||
*out = *in
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
if in.Filters != nil {
|
||||
|
|
@ -653,7 +639,7 @@ func (in *Uninstall) DeepCopyInto(out *Uninstall) {
|
|||
*out = *in
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
if in.DeletionPropagation != nil {
|
||||
|
|
@ -678,7 +664,7 @@ func (in *Upgrade) DeepCopyInto(out *Upgrade) {
|
|||
*out = *in
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(metav1.Duration)
|
||||
*out = new(v1.Duration)
|
||||
**out = **in
|
||||
}
|
||||
if in.Remediation != nil {
|
||||
|
|
|
|||
|
|
@ -581,109 +581,6 @@ spec:
|
|||
- patch
|
||||
type: object
|
||||
type: array
|
||||
patchesJson6902:
|
||||
description: |-
|
||||
JSON 6902 patches, defined as inline YAML objects.
|
||||
Deprecated: use Patches instead.
|
||||
items:
|
||||
description: JSON6902Patch contains a JSON6902 patch and
|
||||
the target the patch should be applied to.
|
||||
properties:
|
||||
patch:
|
||||
description: Patch contains the JSON6902 patch document
|
||||
with an array of operation objects.
|
||||
items:
|
||||
description: |-
|
||||
JSON6902 is a JSON6902 operation object.
|
||||
https://datatracker.ietf.org/doc/html/rfc6902#section-4
|
||||
properties:
|
||||
from:
|
||||
description: |-
|
||||
From contains a JSON-pointer value that references a location within the target document where the operation is
|
||||
performed. The meaning of the value depends on the value of Op, and is NOT taken into account by all operations.
|
||||
type: string
|
||||
op:
|
||||
description: |-
|
||||
Op indicates the operation to perform. Its value MUST be one of "add", "remove", "replace", "move", "copy", or
|
||||
"test".
|
||||
https://datatracker.ietf.org/doc/html/rfc6902#section-4
|
||||
enum:
|
||||
- test
|
||||
- remove
|
||||
- add
|
||||
- replace
|
||||
- move
|
||||
- copy
|
||||
type: string
|
||||
path:
|
||||
description: |-
|
||||
Path contains the JSON-pointer value that references a location within the target document where the operation
|
||||
is performed. The meaning of the value depends on the value of Op.
|
||||
type: string
|
||||
value:
|
||||
description: |-
|
||||
Value contains a valid JSON structure. The meaning of the value depends on the value of Op, and is NOT taken into
|
||||
account by all operations.
|
||||
x-kubernetes-preserve-unknown-fields: true
|
||||
required:
|
||||
- op
|
||||
- path
|
||||
type: object
|
||||
type: array
|
||||
target:
|
||||
description: Target points to the resources that the
|
||||
patch document should be applied to.
|
||||
properties:
|
||||
annotationSelector:
|
||||
description: |-
|
||||
AnnotationSelector is a string that follows the label selection expression
|
||||
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
|
||||
It matches with the resource annotations.
|
||||
type: string
|
||||
group:
|
||||
description: |-
|
||||
Group is the API group to select resources from.
|
||||
Together with Version and Kind it is capable of unambiguously identifying and/or selecting resources.
|
||||
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
|
||||
type: string
|
||||
kind:
|
||||
description: |-
|
||||
Kind of the API Group to select resources from.
|
||||
Together with Group and Version it is capable of unambiguously
|
||||
identifying and/or selecting resources.
|
||||
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
|
||||
type: string
|
||||
labelSelector:
|
||||
description: |-
|
||||
LabelSelector is a string that follows the label selection expression
|
||||
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
|
||||
It matches with the resource labels.
|
||||
type: string
|
||||
name:
|
||||
description: Name to match resources with.
|
||||
type: string
|
||||
namespace:
|
||||
description: Namespace to select resources from.
|
||||
type: string
|
||||
version:
|
||||
description: |-
|
||||
Version of the API Group to select resources from.
|
||||
Together with Group and Kind it is capable of unambiguously identifying and/or selecting resources.
|
||||
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
|
||||
type: string
|
||||
type: object
|
||||
required:
|
||||
- patch
|
||||
- target
|
||||
type: object
|
||||
type: array
|
||||
patchesStrategicMerge:
|
||||
description: |-
|
||||
Strategic merge patches, defined as inline YAML objects.
|
||||
Deprecated: use Patches instead.
|
||||
items:
|
||||
x-kubernetes-preserve-unknown-fields: true
|
||||
type: array
|
||||
type: object
|
||||
type: object
|
||||
type: array
|
||||
|
|
|
|||
|
|
@ -16,20 +16,20 @@ spec:
|
|||
fullnameOverride: mypodinfo
|
||||
postRenderers:
|
||||
- kustomize:
|
||||
patchesStrategicMerge:
|
||||
- kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: mypodinfo
|
||||
labels:
|
||||
xxxx: yyyy
|
||||
patchesJson6902:
|
||||
patches:
|
||||
- patch: |
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: mypodinfo
|
||||
labels:
|
||||
xxxx: yyyy
|
||||
- target:
|
||||
group: apps
|
||||
version: v1
|
||||
kind: Deployment
|
||||
name: mypodinfo
|
||||
patch:
|
||||
- op: add
|
||||
path: /metadata/labels/yyyy
|
||||
value: xxxx
|
||||
patch: |
|
||||
- op: add
|
||||
path: /metadata/labels/yyyy
|
||||
value: xxxx
|
||||
|
|
|
|||
|
|
@ -1983,36 +1983,6 @@ capable of targeting objects based on kind, label and annotation selectors.</p>
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>patchesStrategicMerge</code><br>
|
||||
<em>
|
||||
<a href="https://pkg.go.dev/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1?tab=doc#JSON">
|
||||
[]Kubernetes pkg/apis/apiextensions/v1.JSON
|
||||
</a>
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
<em>(Optional)</em>
|
||||
<p>Strategic merge patches, defined as inline YAML objects.
|
||||
Deprecated: use Patches instead.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>patchesJson6902</code><br>
|
||||
<em>
|
||||
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/kustomize#JSON6902Patch">
|
||||
[]github.com/fluxcd/pkg/apis/kustomize.JSON6902Patch
|
||||
</a>
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
<em>(Optional)</em>
|
||||
<p>JSON 6902 patches, defined as inline YAML objects.
|
||||
Deprecated: use Patches instead.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>images</code><br>
|
||||
<em>
|
||||
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/kustomize#Image">
|
||||
|
|
|
|||
|
|
@ -32,10 +32,8 @@ func BuildPostRenderers(rel *v2.HelmRelease) helmpostrender.PostRenderer {
|
|||
for _, r := range rel.Spec.PostRenderers {
|
||||
if r.Kustomize != nil {
|
||||
renderers = append(renderers, &Kustomize{
|
||||
Patches: r.Kustomize.Patches,
|
||||
PatchesStrategicMerge: r.Kustomize.PatchesStrategicMerge,
|
||||
PatchesJSON6902: r.Kustomize.PatchesJSON6902,
|
||||
Images: r.Kustomize.Images,
|
||||
Patches: r.Kustomize.Patches,
|
||||
Images: r.Kustomize.Images,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"encoding/json"
|
||||
"sync"
|
||||
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
"sigs.k8s.io/kustomize/api/krusty"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
kustypes "sigs.k8s.io/kustomize/api/types"
|
||||
|
|
@ -34,12 +33,6 @@ import (
|
|||
type Kustomize struct {
|
||||
// Patches is a list of patches to apply to the rendered manifests.
|
||||
Patches []kustomize.Patch
|
||||
// PatchesStrategicMerge is a list of strategic merge patches to apply to
|
||||
// the rendered manifests.
|
||||
PatchesStrategicMerge []apiextensionsv1.JSON
|
||||
// PatchesJSON6902 is a list of JSON patches to apply to the rendered
|
||||
// manifests.
|
||||
PatchesJSON6902 []kustomize.JSON6902Patch
|
||||
// Images is a list of images to replace in the rendered manifests.
|
||||
Images []kustomize.Image
|
||||
}
|
||||
|
|
@ -66,23 +59,6 @@ func (k *Kustomize) Run(renderedManifests *bytes.Buffer) (modifiedManifests *byt
|
|||
})
|
||||
}
|
||||
|
||||
// Add strategic merge patches.
|
||||
for _, m := range k.PatchesStrategicMerge {
|
||||
cfg.PatchesStrategicMerge = append(cfg.PatchesStrategicMerge, kustypes.PatchStrategicMerge(m.Raw))
|
||||
}
|
||||
|
||||
// Add JSON 6902 patches.
|
||||
for i, m := range k.PatchesJSON6902 {
|
||||
patch, err := json.Marshal(m.Patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.PatchesJson6902 = append(cfg.PatchesJson6902, kustypes.Patch{
|
||||
Patch: string(patch),
|
||||
Target: adaptSelector(&k.PatchesJSON6902[i].Target),
|
||||
})
|
||||
}
|
||||
|
||||
// Write kustomization config to file.
|
||||
kustomization, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ package postrender
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/kustomize"
|
||||
|
|
@ -61,14 +59,12 @@ spec:
|
|||
|
||||
func Test_postRendererKustomize_Run(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
renderedManifests string
|
||||
patches string
|
||||
patchesStrategicMerge string
|
||||
patchesJson6902 string
|
||||
images string
|
||||
expectManifests string
|
||||
expectErr bool
|
||||
name string
|
||||
renderedManifests string
|
||||
patches string
|
||||
images string
|
||||
expectManifests string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "image tag",
|
||||
|
|
@ -121,12 +117,12 @@ spec:
|
|||
{
|
||||
name: "json 6902",
|
||||
renderedManifests: json6902Mock,
|
||||
patchesJson6902: `
|
||||
patches: `
|
||||
- target:
|
||||
version: v1
|
||||
kind: Pod
|
||||
name: json6902
|
||||
patch:
|
||||
patch: |
|
||||
- op: test
|
||||
path: /metadata/annotations/c
|
||||
value: foo
|
||||
|
|
@ -188,33 +184,6 @@ metadata:
|
|||
d: "42"
|
||||
e: "42"
|
||||
name: json6902
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "strategic merge test",
|
||||
renderedManifests: strategicMergeMock,
|
||||
patchesStrategicMerge: `
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nignx:latest
|
||||
`,
|
||||
expectManifests: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: nignx:latest
|
||||
name: nginx
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
|
@ -255,14 +224,12 @@ spec:
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := NewWithT(t)
|
||||
|
||||
spec, err := mockKustomize(tt.patches, tt.patchesStrategicMerge, tt.patchesJson6902, tt.images)
|
||||
spec, err := mockKustomize(tt.patches, tt.images)
|
||||
g.Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
k := &Kustomize{
|
||||
Patches: spec.Patches,
|
||||
PatchesStrategicMerge: spec.PatchesStrategicMerge,
|
||||
PatchesJSON6902: spec.PatchesJSON6902,
|
||||
Images: spec.Images,
|
||||
Patches: spec.Patches,
|
||||
Images: spec.Images,
|
||||
}
|
||||
gotModifiedManifests, err := k.Run(bytes.NewBufferString(tt.renderedManifests))
|
||||
if tt.expectErr {
|
||||
|
|
@ -277,31 +244,17 @@ spec:
|
|||
}
|
||||
}
|
||||
|
||||
func mockKustomize(patches, patchesStrategicMerge, patchesJson6902, images string) (*v2.Kustomize, error) {
|
||||
func mockKustomize(patches, images string) (*v2.Kustomize, error) {
|
||||
var targeted []kustomize.Patch
|
||||
if err := yaml.Unmarshal([]byte(patches), &targeted); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := yaml.YAMLToJSON([]byte(patchesStrategicMerge))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var strategicMerge []v1.JSON
|
||||
if err := json.Unmarshal(b, &strategicMerge); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var json6902 []kustomize.JSON6902Patch
|
||||
if err := yaml.Unmarshal([]byte(patchesJson6902), &json6902); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var imgs []kustomize.Image
|
||||
if err := yaml.Unmarshal([]byte(images), &imgs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v2.Kustomize{
|
||||
Patches: targeted,
|
||||
PatchesStrategicMerge: strategicMerge,
|
||||
PatchesJSON6902: json6902,
|
||||
Images: imgs,
|
||||
Patches: targeted,
|
||||
Images: imgs,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue