diff --git a/go.sum b/go.sum index 4e24d83..7c3054e 100644 --- a/go.sum +++ b/go.sum @@ -186,8 +186,6 @@ github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlT github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sap/go-generics v0.2.53 h1:C5MltWIx6MxpgPxQJa2eupGm3Jim4jIfwm/2KOT1BQM= -github.com/sap/go-generics v0.2.53/go.mod h1:xqWmp3jVLGNTmTuPjwdWgNk11pzi0zarA1iqV0om24c= github.com/sap/go-generics v0.2.54 h1:NbWwKMH4w6Gmts2ilvhmKthwMbzHjJn3zDeh4940T5Q= github.com/sap/go-generics v0.2.54/go.mod h1:xqWmp3jVLGNTmTuPjwdWgNk11pzi0zarA1iqV0om24c= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= diff --git a/internal/kustomize/kustomization.go b/internal/kustomize/kustomization.go index 12e8002..9ec4665 100644 --- a/internal/kustomize/kustomization.go +++ b/internal/kustomize/kustomization.go @@ -28,7 +28,7 @@ import ( "k8s.io/client-go/discovery" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/kustomize/api/konfig" - kustypes "sigs.k8s.io/kustomize/api/types" + kusttypes "sigs.k8s.io/kustomize/api/types" kustfsys "sigs.k8s.io/kustomize/kyaml/filesys" kyaml "sigs.k8s.io/yaml" @@ -408,10 +408,10 @@ func generateKustomization(fsys kustfsys.FileSystem, kustomizationPath string) ( return nil, err } - kustomization := kustypes.Kustomization{ - TypeMeta: kustypes.TypeMeta{ - APIVersion: kustypes.KustomizationVersion, - Kind: kustypes.KustomizationKind, + kustomization := kusttypes.Kustomization{ + TypeMeta: kusttypes.TypeMeta{ + APIVersion: kusttypes.KustomizationVersion, + Kind: kusttypes.KustomizationKind, }, Resources: resources, } diff --git a/pkg/manifests/kustomize/generator.go b/pkg/manifests/kustomize/generator.go index 346efaa..fbc8a33 100644 --- a/pkg/manifests/kustomize/generator.go +++ b/pkg/manifests/kustomize/generator.go @@ -15,7 +15,7 @@ import ( utilyaml "k8s.io/apimachinery/pkg/util/yaml" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/kustomize/api/krusty" - kustypes "sigs.k8s.io/kustomize/api/types" + kusttypes "sigs.k8s.io/kustomize/api/types" kustfsys "sigs.k8s.io/kustomize/kyaml/filesys" "github.com/sap/component-operator-runtime/internal/kustomize" @@ -65,8 +65,8 @@ func NewKustomizeGenerator(fsys fs.FS, kustomizationPath string, _ client.Client } kustomizerOptions := &krusty.Options{ - LoadRestrictions: kustypes.LoadRestrictionsNone, - PluginConfig: kustypes.DisabledPluginConfig(), + LoadRestrictions: kusttypes.LoadRestrictionsNone, + PluginConfig: kusttypes.DisabledPluginConfig(), } kustomizer := krusty.MakeKustomizer(kustomizerOptions) diff --git a/pkg/manifests/transformer.go b/pkg/manifests/transformer.go index d95fbc4..95dc653 100644 --- a/pkg/manifests/transformer.go +++ b/pkg/manifests/transformer.go @@ -14,6 +14,7 @@ import ( "github.com/Masterminds/sprig/v3" + "sigs.k8s.io/controller-runtime/pkg/client" kyaml "sigs.k8s.io/yaml" "github.com/sap/component-operator-runtime/internal/templatex" @@ -70,3 +71,27 @@ func (t *TemplateParameterTransformer) TransformParameters(namespace string, nam } return transformedParameters, nil } + +type SubstitutionObjectTransformer struct{} + +var _ ObjectTransformer = &SubstitutionObjectTransformer{} + +func NewSubstitutionObjectTransformer(substitutions map[string]string, selector types.Selector[client.Object]) (*SubstitutionObjectTransformer, error) { + return &SubstitutionObjectTransformer{}, nil +} + +func (t *SubstitutionObjectTransformer) TransformObjects(namespace string, name string, objects []client.Object) ([]client.Object, error) { + return objects, nil +} + +type KustomizeObjectTransformer struct{} + +var _ ObjectTransformer = &KustomizeObjectTransformer{} + +func NewKustomizeObjectTransformer(patches []KustomizePatch, images []KustomizeImage) (*KustomizeObjectTransformer, error) { + return &KustomizeObjectTransformer{}, nil +} + +func (t *KustomizeObjectTransformer) TransformObjects(namespace string, name string, objects []client.Object) ([]client.Object, error) { + return objects, nil +} diff --git a/pkg/manifests/types.go b/pkg/manifests/types.go index 66b39b6..0a09175 100644 --- a/pkg/manifests/types.go +++ b/pkg/manifests/types.go @@ -47,3 +47,34 @@ type ObjectTransformer interface { type Decryptor interface { Decrypt(input []byte, path string) ([]byte, error) } + +// +kubebuilder:object:generate=true + +// Kustomize patch specification, basically a subset of sigs.k8s.io/kustomize/api/types#Patch +type KustomizePatch struct { + Patch string `json:"patch,omitempty"` + Target *KustomizeSelector `json:"target,omitempty"` +} + +// +kubebuilder:object:generate=true + +// Kustomize object selector; corresponds to sigs.k8s.io/kustomize/api/types#Selector +type KustomizeSelector struct { + Group string `json:"group,omitempty"` + Version string `json:"version,omitempty"` + Kind string `json:"kind,omitempty"` + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` + AnnotationSelector string `json:"annotationSelector,omitempty"` + LabelSelector string `json:"labelSelector,omitempty"` +} + +// +kubebuilder:object:generate=true + +// Kustomize image modifier specification, basically a subset of sigs.k8s.io/kustomize/api/types#Image +type KustomizeImage struct { + Name string `json:"name"` + NewName string `json:"newName,omitempty"` + NewTag string `json:"newTag,omitempty"` + Digest string `json:"digest,omitempty"` +} diff --git a/pkg/manifests/zz_generated.deepcopy.go b/pkg/manifests/zz_generated.deepcopy.go new file mode 100644 index 0000000..d4297d1 --- /dev/null +++ b/pkg/manifests/zz_generated.deepcopy.go @@ -0,0 +1,62 @@ +//go:build !ignore_autogenerated + +/* +SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and component-operator-runtime contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package manifests + +import () + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KustomizeImage) DeepCopyInto(out *KustomizeImage) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KustomizeImage. +func (in *KustomizeImage) DeepCopy() *KustomizeImage { + if in == nil { + return nil + } + out := new(KustomizeImage) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KustomizePatch) DeepCopyInto(out *KustomizePatch) { + *out = *in + if in.Target != nil { + in, out := &in.Target, &out.Target + *out = new(KustomizeSelector) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KustomizePatch. +func (in *KustomizePatch) DeepCopy() *KustomizePatch { + if in == nil { + return nil + } + out := new(KustomizePatch) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KustomizeSelector) DeepCopyInto(out *KustomizeSelector) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KustomizeSelector. +func (in *KustomizeSelector) DeepCopy() *KustomizeSelector { + if in == nil { + return nil + } + out := new(KustomizeSelector) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/types/selector.go b/pkg/types/selector.go new file mode 100644 index 0000000..b9a5ced --- /dev/null +++ b/pkg/types/selector.go @@ -0,0 +1,18 @@ +/* +SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and component-operator-runtime contributors +SPDX-License-Identifier: Apache-2.0 +*/ + +package types + +type Selector[T any] interface { + Matches(object T) bool +} + +type SelectorFunc[T any] func(object T) bool + +func (s SelectorFunc[T]) Matches(object T) bool { + return s(object) +} + +var _ Selector[any] = SelectorFunc[any](nil)