From 5a743fd2bcf60a5c9e9db93d65105c1daf8c3918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20B=C3=A4hler?= Date: Wed, 12 Jun 2024 19:32:44 +0200 Subject: [PATCH] feat(api): add ignore drift definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Oliver Bähler --- api/v1alpha1/ignore_type.go | 28 ++++++++++ api/v1alpha1/resourcesummary_type.go | 4 ++ api/v1alpha1/zz_generated.deepcopy.go | 33 +++++++++++ ...b.projectsveltos.io_resourcesummaries.yaml | 55 +++++++++++++++++++ go.mod | 1 + go.sum | 3 + lib/crd/resourcesummaries.go | 55 +++++++++++++++++++ 7 files changed, 179 insertions(+) create mode 100644 api/v1alpha1/ignore_type.go diff --git a/api/v1alpha1/ignore_type.go b/api/v1alpha1/ignore_type.go new file mode 100644 index 0000000..b7032b5 --- /dev/null +++ b/api/v1alpha1/ignore_type.go @@ -0,0 +1,28 @@ +/* +Copyright 2022. projectsveltos.io. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "github.com/fluxcd/pkg/apis/kustomize" +) + +type IgnoreDriftItem struct { + // +required + Paths []string `json:"paths"` + // +optional + Target *kustomize.Selector `json:"target,omitempty"` +} diff --git a/api/v1alpha1/resourcesummary_type.go b/api/v1alpha1/resourcesummary_type.go index 6c55f8d..6efe396 100644 --- a/api/v1alpha1/resourcesummary_type.go +++ b/api/v1alpha1/resourcesummary_type.go @@ -97,6 +97,10 @@ type ResourceSummarySpec struct { // Resources deployed by ClusterSummary because of referenced Helm charts // +optional ChartResources []HelmResources `json:"chartResources,omitempty"` + + // Resource specs ignored for drift detection + // +optional + IgnoreDrift []IgnoreDriftItem `json:"ignoreDrift,omitempty"` } // ResourceSummaryStatus defines the status of ResourceSummary diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 9443627..b0904dc 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package v1alpha1 import ( + "github.com/fluxcd/pkg/apis/kustomize" "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -1098,6 +1099,31 @@ func (in *HelmResources) DeepCopy() *HelmResources { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IgnoreDriftItem) DeepCopyInto(out *IgnoreDriftItem) { + *out = *in + if in.Paths != nil { + in, out := &in.Paths, &out.Paths + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Target != nil { + in, out := &in.Target, &out.Target + *out = new(kustomize.Selector) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IgnoreDriftItem. +func (in *IgnoreDriftItem) DeepCopy() *IgnoreDriftItem { + if in == nil { + return nil + } + out := new(IgnoreDriftItem) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KubernetesVersionConstraint) DeepCopyInto(out *KubernetesVersionConstraint) { *out = *in @@ -1574,6 +1600,13 @@ func (in *ResourceSummarySpec) DeepCopyInto(out *ResourceSummarySpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.IgnoreDrift != nil { + in, out := &in.IgnoreDrift, &out.IgnoreDrift + *out = make([]IgnoreDriftItem, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSummarySpec. diff --git a/config/crd/bases/lib.projectsveltos.io_resourcesummaries.yaml b/config/crd/bases/lib.projectsveltos.io_resourcesummaries.yaml index 89cf147..e425e0e 100644 --- a/config/crd/bases/lib.projectsveltos.io_resourcesummaries.yaml +++ b/config/crd/bases/lib.projectsveltos.io_resourcesummaries.yaml @@ -94,6 +94,61 @@ spec: - releaseNamespace type: object type: array + ignoreDrift: + description: Resource specs ignored for drift detection + items: + properties: + paths: + items: + type: string + type: array + target: + description: |- + Selector specifies a set of resources. Any resource that matches intersection of all conditions is included in this + set. + 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: + - paths + type: object + type: array kustomizeResources: description: |- KustomizeResources deployed by ClusterSummary because of referenced diff --git a/go.mod b/go.mod index b91ba14..df31c57 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v5.7.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect + github.com/fluxcd/pkg/apis/kustomize v1.5.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect diff --git a/go.sum b/go.sum index e106753..7317b31 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/fluxcd/pkg/apis/kustomize v1.5.0 h1:ah4sfqccnio+/5Edz/tVz6LetFhiBoDzXAElj6fFCzU= +github.com/fluxcd/pkg/apis/kustomize v1.5.0/go.mod h1:nEzhnhHafhWOUUV8VMFLojUOH+HHDEsL75y54mt/c30= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= @@ -94,6 +96,7 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/lib/crd/resourcesummaries.go b/lib/crd/resourcesummaries.go index 6cd4eda..cc17edc 100644 --- a/lib/crd/resourcesummaries.go +++ b/lib/crd/resourcesummaries.go @@ -113,6 +113,61 @@ spec: - releaseNamespace type: object type: array + ignoreDrift: + description: Resource specs ignored for drift detection + items: + properties: + paths: + items: + type: string + type: array + target: + description: |- + Selector specifies a set of resources. Any resource that matches intersection of all conditions is included in this + set. + 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: + - paths + type: object + type: array kustomizeResources: description: |- KustomizeResources deployed by ClusterSummary because of referenced