From b2248674fa2ccb3c8263d07f2c2fb895ad6b8c72 Mon Sep 17 00:00:00 2001 From: Matias Frank Jensen Date: Mon, 6 May 2024 14:32:24 +0200 Subject: [PATCH] :recycle: Changes/renames to platform CRDs --- cmd/rig-proto-gen/main.go | 2 +- docs/docs/api/platform-api.md | 109 ++++++------ pkg/api/platform/v1/conversion.go | 32 ++-- pkg/api/platform/v1/conversion_test.go | 28 ++-- pkg/api/platform/v1/types.go | 54 +++--- pkg/api/platform/v1/zz_generated.deepcopy.go | 167 ++++++++++--------- pkg/obj/merge.go | 14 +- pkg/obj/merge_test.go | 116 +++++++------ proto/rig/platform/v1/generated.proto | 35 ++-- 9 files changed, 284 insertions(+), 273 deletions(-) diff --git a/cmd/rig-proto-gen/main.go b/cmd/rig-proto-gen/main.go index eac5da5a2..61956e5b3 100644 --- a/cmd/rig-proto-gen/main.go +++ b/cmd/rig-proto-gen/main.go @@ -35,7 +35,7 @@ var ( "github.com/rigdev/rig/pkg/api/platform/v1": "platform/v1", } compiledTypes = []any{ - v1.CapsuleStar{}, + v1.Capsule{}, v1.CapsuleEnvironment{}, v1.Environment{}, v1.Project{}, diff --git a/docs/docs/api/platform-api.md b/docs/docs/api/platform-api.md index ee4d64ca9..3220e8fa0 100644 --- a/docs/docs/api/platform-api.md +++ b/docs/docs/api/platform-api.md @@ -7834,9 +7834,9 @@ Empty response for updating users settings for the Rig project. - + -### CapsuleEnvironment +### Capsule @@ -7846,76 +7846,54 @@ Empty response for updating users settings for the Rig project. | apiVersion | [string](#string) | | | | name | [string](#string) | | | | project | [string](#string) | | | -| environment | [string](#string) | | | -| spec | [CapsuleSpecExtension](#platform-v1-CapsuleSpecExtension) | | | - - - - - - - - -### CapsuleSpecExtension - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| kind | [string](#string) | | | -| apiVersion | [string](#string) | | | -| image | [string](#string) | | | -| command | [string](#string) | | | -| args | [string](#string) | repeated | | -| interfaces | [v1alpha2.CapsuleInterface](#v1alpha2-CapsuleInterface) | repeated | | -| configFiles | [ConfigFile](#platform-v1-ConfigFile) | repeated | | -| environmentVariables | [EnvironmentVariables](#platform-v1-EnvironmentVariables) | | | -| scale | [v1alpha2.CapsuleScale](#v1alpha2-CapsuleScale) | | | -| nodeSelector | [CapsuleSpecExtension.NodeSelectorEntry](#platform-v1-CapsuleSpecExtension-NodeSelectorEntry) | repeated | | -| cronJobs | [v1alpha2.CronJob](#v1alpha2-CronJob) | repeated | | -| annotations | [CapsuleSpecExtension.AnnotationsEntry](#platform-v1-CapsuleSpecExtension-AnnotationsEntry) | repeated | | -| autoAddRigServiceAccounts | [bool](#bool) | | | +| spec | [CapsuleSpec](#platform-v1-CapsuleSpec) | | | +| environments | [Capsule.EnvironmentsEntry](#platform-v1-Capsule-EnvironmentsEntry) | repeated | | +| environmentRefs | [string](#string) | repeated | | - + -### CapsuleSpecExtension.AnnotationsEntry +### Capsule.EnvironmentsEntry | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | key | [string](#string) | | | -| value | [string](#string) | | | +| value | [CapsuleSpec](#platform-v1-CapsuleSpec) | | | - + -### CapsuleSpecExtension.NodeSelectorEntry +### CapsuleEnvironment | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| key | [string](#string) | | | -| value | [string](#string) | | | +| kind | [string](#string) | | | +| apiVersion | [string](#string) | | | +| name | [string](#string) | | | +| project | [string](#string) | | | +| environment | [string](#string) | | | +| spec | [CapsuleSpec](#platform-v1-CapsuleSpec) | | | - + -### CapsuleStar +### CapsuleSpec @@ -7923,27 +7901,32 @@ Empty response for updating users settings for the Rig project. | ----- | ---- | ----- | ----------- | | kind | [string](#string) | | | | apiVersion | [string](#string) | | | -| name | [string](#string) | | | -| project | [string](#string) | | | -| capsuleBase | [CapsuleSpecExtension](#platform-v1-CapsuleSpecExtension) | | | -| environments | [string](#string) | repeated | | +| annotations | [CapsuleSpec.AnnotationsEntry](#platform-v1-CapsuleSpec-AnnotationsEntry) | repeated | | +| image | [string](#string) | | | +| command | [string](#string) | | | +| args | [string](#string) | repeated | | +| interfaces | [v1alpha2.CapsuleInterface](#v1alpha2-CapsuleInterface) | repeated | | +| files | [File](#platform-v1-File) | repeated | | +| env | [EnvironmentVariables](#platform-v1-EnvironmentVariables) | | | +| scale | [v1alpha2.CapsuleScale](#v1alpha2-CapsuleScale) | | | +| cronJobs | [v1alpha2.CronJob](#v1alpha2-CronJob) | repeated | | +| autoAddRigServiceAccounts | [bool](#bool) | | | - + -### ConfigFile +### CapsuleSpec.AnnotationsEntry | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| path | [string](#string) | | | -| content | [bytes](#bytes) | | | -| isSecret | [bool](#bool) | | | +| key | [string](#string) | | | +| value | [string](#string) | | | @@ -7963,8 +7946,8 @@ Empty response for updating users settings for the Rig project. | name | [string](#string) | | | | namespaceTemplate | [string](#string) | | | | operatorVersion | [string](#string) | | | -| clusterID | [string](#string) | | | -| capsuleBase | [ProjEnvCapsuleBase](#platform-v1-ProjEnvCapsuleBase) | | | +| cluster | [string](#string) | | | +| spec | [ProjEnvCapsuleBase](#platform-v1-ProjEnvCapsuleBase) | | | @@ -8019,6 +8002,24 @@ Empty response for updating users settings for the Rig project. + + +### File + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| path | [string](#string) | | | +| asSecret | [bool](#bool) | | | +| bytes | [bytes](#bytes) | | | +| string | [string](#string) | | | + + + + + + ### ProjEnvCapsuleBase @@ -8027,8 +8028,8 @@ Empty response for updating users settings for the Rig project. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| configFiles | [ConfigFile](#platform-v1-ConfigFile) | repeated | | -| environmentVariables | [EnvironmentVariables](#platform-v1-EnvironmentVariables) | | | +| files | [File](#platform-v1-File) | repeated | | +| env | [EnvironmentVariables](#platform-v1-EnvironmentVariables) | | | @@ -8047,7 +8048,7 @@ Empty response for updating users settings for the Rig project. | apiVersion | [string](#string) | | | | name | [string](#string) | | | | environments | [string](#string) | repeated | | -| capsuleBase | [ProjEnvCapsuleBase](#platform-v1-ProjEnvCapsuleBase) | | | +| spec | [ProjEnvCapsuleBase](#platform-v1-ProjEnvCapsuleBase) | | | diff --git a/pkg/api/platform/v1/conversion.go b/pkg/api/platform/v1/conversion.go index 09f959f4f..c3adb1e62 100644 --- a/pkg/api/platform/v1/conversion.go +++ b/pkg/api/platform/v1/conversion.go @@ -17,9 +17,9 @@ import ( k8sresource "k8s.io/apimachinery/pkg/api/resource" ) -func RolloutConfigToCapsuleSpecExtension(rc *capsule.RolloutConfig) (*platformv1.CapsuleSpecExtension, error) { - spec := &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", +func RolloutConfigToCapsuleSpec(rc *capsule.RolloutConfig) (*platformv1.CapsuleSpec, error) { + spec := &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", // TODO Image: rc.GetImageId(), Scale: &v1alpha2.CapsuleScale{ @@ -34,10 +34,10 @@ func RolloutConfigToCapsuleSpecExtension(rc *capsule.RolloutConfig) (*platformv1 } for _, cf := range rc.GetConfigFiles() { - spec.ConfigFiles = append(spec.ConfigFiles, &platformv1.ConfigFile{ + spec.Files = append(spec.Files, &platformv1.File{ Path: cf.GetPath(), - Content: cf.GetContent(), - IsSecret: cf.GetIsSecret(), + Bytes: cf.GetContent(), + AsSecret: cf.GetIsSecret(), }) } @@ -127,7 +127,7 @@ func HorizontalScaleConversion(horizontal *capsule.HorizontalScale, replicas uin return res } -func FeedContainerSettings(spec *platformv1.CapsuleSpecExtension, containerSettings *capsule.ContainerSettings) error { +func FeedContainerSettings(spec *platformv1.CapsuleSpec, containerSettings *capsule.ContainerSettings) error { if spec.Scale == nil { spec.Scale = &v1alpha2.CapsuleScale{} } @@ -136,7 +136,7 @@ func FeedContainerSettings(spec *platformv1.CapsuleSpecExtension, containerSetti containerSettings.GetResources().GetLimits(), containerSettings.GetResources().GetGpuLimits(), ) - spec.EnvironmentVariables = &platformv1.EnvironmentVariables{ + spec.Env = &platformv1.EnvironmentVariables{ Direct: maps.Clone(containerSettings.GetEnvironmentVariables()), } @@ -145,7 +145,7 @@ func FeedContainerSettings(spec *platformv1.CapsuleSpecExtension, containerSetti if err != nil { return err } - spec.EnvironmentVariables.Sources = append(spec.EnvironmentVariables.Sources, ref) + spec.Env.Sources = append(spec.Env.Sources, ref) } spec.Command = containerSettings.GetCommand() spec.Args = containerSettings.GetArgs() @@ -301,18 +301,18 @@ func makeVerticalScale( return vs } -func CapsuleSpecExtensionToRolloutConfig(spec *platformv1.CapsuleSpecExtension) (*capsule.RolloutConfig, error) { +func CapsuleSpecToRolloutConfig(spec *platformv1.CapsuleSpec) (*capsule.RolloutConfig, error) { config := &capsule.RolloutConfig{ ImageId: spec.GetImage(), Network: makeNetworks(spec.GetInterfaces()), ContainerSettings: &capsule.ContainerSettings{ - EnvironmentVariables: maps.Clone(spec.GetEnvironmentVariables().GetDirect()), + EnvironmentVariables: maps.Clone(spec.GetEnv().GetDirect()), Command: spec.GetCommand(), Args: spec.GetArgs(), - EnvironmentSources: makeEnvironmentSources(spec.GetEnvironmentVariables().GetSources()), + EnvironmentSources: makeEnvironmentSources(spec.GetEnv().GetSources()), }, AutoAddRigServiceAccounts: spec.GetAutoAddRigServiceAccounts(), - ConfigFiles: makeConfigFiles(spec.GetConfigFiles()), + ConfigFiles: makeConfigFiles(spec.GetFiles()), HorizontalScale: makeHorizontalScale(spec.GetScale().GetHorizontal()), CronJobs: makeCronJobs(spec.GetCronJobs()), Annotations: maps.Clone(spec.GetAnnotations()), @@ -444,14 +444,14 @@ func makeHorizontalScale(spec *v1alpha2.HorizontalScale) *capsule.HorizontalScal return res } -func makeConfigFiles(configFiles []*platformv1.ConfigFile) []*capsule.ConfigFile { +func makeConfigFiles(configFiles []*platformv1.File) []*capsule.ConfigFile { var res []*capsule.ConfigFile for _, c := range configFiles { res = append(res, &capsule.ConfigFile{ Path: c.GetPath(), - Content: c.GetContent(), - IsSecret: c.GetIsSecret(), + Content: c.GetBytes(), + IsSecret: c.GetAsSecret(), }) } diff --git a/pkg/api/platform/v1/conversion_test.go b/pkg/api/platform/v1/conversion_test.go index 2da87da26..063527a88 100644 --- a/pkg/api/platform/v1/conversion_test.go +++ b/pkg/api/platform/v1/conversion_test.go @@ -142,8 +142,8 @@ var ( }}, Annotations: map[string]string{"annotation": "value"}, } - spec = &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + spec = &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", Image: "image", Command: "cmd", @@ -229,18 +229,18 @@ var ( }, }, }, - EnvironmentVariables: &platformv1.EnvironmentVariables{ + Env: &platformv1.EnvironmentVariables{ Direct: map[string]string{"key1": "value1"}, Sources: []*platformv1.EnvironmentSource{{ Name: "some-map", Kind: "ConfigMap", }}, }, - ConfigFiles: []*platformv1.ConfigFile{ + Files: []*platformv1.File{ { Path: "/etc/file1.yaml", - Content: []byte("hej"), - IsSecret: false, + Bytes: []byte("hej"), + AsSecret: false, }, }, CronJobs: []*v1alpha2.CronJob{ @@ -260,28 +260,28 @@ var ( } ) -func Test_RolloutConfigToCapsuleSpecExtension(t *testing.T) { - spec2, err := RolloutConfigToCapsuleSpecExtension(rolloutConfig) +func Test_RolloutConfigToCapsuleSpec(t *testing.T) { + spec2, err := RolloutConfigToCapsuleSpec(rolloutConfig) require.NoError(t, err) require.Equal(t, spec, spec2) } -func Test_CapsuleSpecExtensionToRolloutConfig(t *testing.T) { - config, err := CapsuleSpecExtensionToRolloutConfig(spec) +func Test_CapsuleSpecToRolloutConfig(t *testing.T) { + config, err := CapsuleSpecToRolloutConfig(spec) require.NoError(t, err) require.Equal(t, rolloutConfig, config) } func Test_conversion_both_ways(t *testing.T) { - config, err := CapsuleSpecExtensionToRolloutConfig(spec) + config, err := CapsuleSpecToRolloutConfig(spec) require.NoError(t, err) - spec2, err := RolloutConfigToCapsuleSpecExtension(config) + spec2, err := RolloutConfigToCapsuleSpec(config) require.NoError(t, err) require.Equal(t, spec, spec2) - spec2, err = RolloutConfigToCapsuleSpecExtension(rolloutConfig) + spec2, err = RolloutConfigToCapsuleSpec(rolloutConfig) require.NoError(t, err) - config, err = CapsuleSpecExtensionToRolloutConfig(spec2) + config, err = CapsuleSpecToRolloutConfig(spec2) require.NoError(t, err) require.Equal(t, rolloutConfig, config) diff --git a/pkg/api/platform/v1/types.go b/pkg/api/platform/v1/types.go index e9450e745..59a3ea169 100644 --- a/pkg/api/platform/v1/types.go +++ b/pkg/api/platform/v1/types.go @@ -16,9 +16,9 @@ type Environment struct { Name string `json:"name" protobuf:"3"` NamespaceTemplate string `json:"namespaceTemplate" protobuf:"4"` OperatorVersion string `json:"operatorVersion" protobuf:"5"` - ClusterID string `json:"clusterID" protobuf:"6"` + Cluster string `json:"cluster" protobuf:"6"` // Environment level defaults - CapsuleBase ProjEnvCapsuleBase `json:"capsuleBase" protobuf:"7"` + Spec ProjEnvCapsuleBase `json:"spec" protobuf:"7"` } // +kubebuilder:object:root=true @@ -31,14 +31,14 @@ type Project struct { // A capsule is only allowed in an environment if its project references the environment in this list Environments []string `json:"environments" protobuf:"4"` // Project level defaults - CapsuleBase ProjEnvCapsuleBase `json:"capsuleBase" protobuf:"5"` + Spec ProjEnvCapsuleBase `json:"spec" protobuf:"5"` } //+kubebuilder:object:=true type ProjEnvCapsuleBase struct { - ConfigFiles []ConfigFile `json:"configFiles,omitempty" protobuf:"1"` - EnvironmentVariables EnvironmentVariables `json:"environmentVariables,omitempty" protobuf:"2"` + Files []File `json:"files,omitempty" protobuf:"1"` + Env EnvironmentVariables `json:"env,omitempty" protobuf:"2"` } type EnvironmentSource struct { @@ -56,7 +56,7 @@ var ( // +kubebuilder:object:root=true // +kubebuilder:storageversion -type CapsuleStar struct { +type Capsule struct { metav1.TypeMeta `json:",inline"` // Name,Project is unique Name string `json:"name" protobuf:"3"` @@ -64,32 +64,36 @@ type CapsuleStar struct { // Will throw an error (in the platform) if the Project does not exist Project string `json:"project" protobuf:"4"` // Capsule-level defaults - CapsuleBase CapsuleSpecExtension `json:"capsuleBase" protobuf:"5"` - Environments []string `json:"environments" protobuf:"6"` + Spec CapsuleSpec `json:"spec" protobuf:"5"` + Environments map[string]CapsuleSpec `json:"environments" protobuf:"6"` + EnvironmentRefs []string `json:"environmentRefs" protobuf:"7"` } // +kubebuilder:object:root=true - +// TODO Different name type CapsuleEnvironment struct { metav1.TypeMeta `json:",inline"` // Name,Project,Environment is unique - // Project,Name referes to an existing CapsuleStar type with the given name and project - // Will throw an error (in the platform) if the CapsuleStar does not exist + // Project,Name referes to an existing Capsule type with the given name and project + // Will throw an error (in the platform) if the Capsule does not exist Name string `json:"name" protobuf:"3"` // Project references an existing Project type with the given name // Will throw an error (in the platform) if the Project does not exist Project string `json:"project" protobuf:"4"` // Environment references an existing Environment type with the given name // Will throw an error (in the platform) if the Environment does not exist - // The environment also needs to be present in the parent CapsuleStar - Environment string `json:"environment" protobuf:"5"` - Spec CapsuleSpecExtension `json:"spec" protobuf:"6"` + // The environment also needs to be present in the parent Capsule + Environment string `json:"environment" protobuf:"5"` + Spec CapsuleSpec `json:"spec" protobuf:"6"` } // +kubebuilder:object:root=true -type CapsuleSpecExtension struct { +type CapsuleSpec struct { metav1.TypeMeta `json:",inline"` + + Annotations map[string]string `json:"annotations" protobuf:"11"` + // Image specifies what image the Capsule should run. Image string `json:"image" protobuf:"3"` @@ -111,20 +115,16 @@ type CapsuleSpecExtension struct { // Files is a list of files to mount in the container. These can either be // based on ConfigMaps or Secrets. - ConfigFiles []ConfigFile `json:"configFiles" protobuf:"7" patchMergeKey:"path" patchStrategy:"merge"` + Files []File `json:"files" protobuf:"7" patchMergeKey:"path" patchStrategy:"merge"` - EnvironmentVariables EnvironmentVariables `json:"environmentVariables" protobuf:"12"` + Env EnvironmentVariables `json:"env" protobuf:"12"` // Scale specifies the scaling of the Capsule. Scale v1alpha2.CapsuleScale `json:"scale,omitempty" protobuf:"8"` - // NodeSelector is a selector for what nodes the Capsule should live on. - NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"9"` - CronJobs []v1alpha2.CronJob `json:"cronJobs,omitempty" protobuf:"10" patchMergeKey:"name" patchStrategy:"replace"` - Annotations map[string]string `json:"annotations" protobuf:"11"` - + // TODO Move to plugin AutoAddRigServiceAccounts bool `json:"autoAddRigServiceAccounts" protobuf:"13"` } @@ -133,8 +133,10 @@ type EnvironmentVariables struct { Sources []EnvironmentSource `json:"sources" protobuf:"2"` } -type ConfigFile struct { - Path string `json:"path,omitempty" protobuf:"1"` - Content []byte `json:"content,omitempty" protobuf:"2"` - IsSecret bool `json:"isSecret,omitempty" protobuf:"3"` +type File struct { + Path string `json:"path,omitempty" protobuf:"1"` + AsSecret bool `json:"asSecret,omitempty" protobuf:"3"` + Bytes *[]byte `json:"bytes,omitempty" protobuf:"4"` + String *string `json:"string,omitempty" protobuf:"5"` + // TODO Ref } diff --git a/pkg/api/platform/v1/zz_generated.deepcopy.go b/pkg/api/platform/v1/zz_generated.deepcopy.go index 61c111f53..777413fa4 100644 --- a/pkg/api/platform/v1/zz_generated.deepcopy.go +++ b/pkg/api/platform/v1/zz_generated.deepcopy.go @@ -9,6 +9,43 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Capsule) DeepCopyInto(out *Capsule) { + *out = *in + out.TypeMeta = in.TypeMeta + in.Spec.DeepCopyInto(&out.Spec) + if in.Environments != nil { + in, out := &in.Environments, &out.Environments + *out = make(map[string]CapsuleSpec, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } + if in.EnvironmentRefs != nil { + in, out := &in.EnvironmentRefs, &out.EnvironmentRefs + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Capsule. +func (in *Capsule) DeepCopy() *Capsule { + if in == nil { + return nil + } + out := new(Capsule) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Capsule) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CapsuleEnvironment) DeepCopyInto(out *CapsuleEnvironment) { *out = *in @@ -35,9 +72,16 @@ func (in *CapsuleEnvironment) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CapsuleSpecExtension) DeepCopyInto(out *CapsuleSpecExtension) { +func (in *CapsuleSpec) DeepCopyInto(out *CapsuleSpec) { *out = *in out.TypeMeta = in.TypeMeta + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.Args != nil { in, out := &in.Args, &out.Args *out = make([]string, len(*in)) @@ -50,22 +94,15 @@ func (in *CapsuleSpecExtension) DeepCopyInto(out *CapsuleSpecExtension) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.ConfigFiles != nil { - in, out := &in.ConfigFiles, &out.ConfigFiles - *out = make([]ConfigFile, len(*in)) + if in.Files != nil { + in, out := &in.Files, &out.Files + *out = make([]File, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } - in.EnvironmentVariables.DeepCopyInto(&out.EnvironmentVariables) + in.Env.DeepCopyInto(&out.Env) in.Scale.DeepCopyInto(&out.Scale) - if in.NodeSelector != nil { - in, out := &in.NodeSelector, &out.NodeSelector - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } if in.CronJobs != nil { in, out := &in.CronJobs, &out.CronJobs *out = make([]v1alpha2.CronJob, len(*in)) @@ -73,88 +110,31 @@ func (in *CapsuleSpecExtension) DeepCopyInto(out *CapsuleSpecExtension) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapsuleSpecExtension. -func (in *CapsuleSpecExtension) DeepCopy() *CapsuleSpecExtension { - if in == nil { - return nil - } - out := new(CapsuleSpecExtension) - in.DeepCopyInto(out) - return out } -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CapsuleSpecExtension) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CapsuleStar) DeepCopyInto(out *CapsuleStar) { - *out = *in - out.TypeMeta = in.TypeMeta - in.CapsuleBase.DeepCopyInto(&out.CapsuleBase) - if in.Environments != nil { - in, out := &in.Environments, &out.Environments - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapsuleStar. -func (in *CapsuleStar) DeepCopy() *CapsuleStar { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapsuleSpec. +func (in *CapsuleSpec) DeepCopy() *CapsuleSpec { if in == nil { return nil } - out := new(CapsuleStar) + out := new(CapsuleSpec) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CapsuleStar) DeepCopyObject() runtime.Object { +func (in *CapsuleSpec) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ConfigFile) DeepCopyInto(out *ConfigFile) { - *out = *in - if in.Content != nil { - in, out := &in.Content, &out.Content - *out = make([]byte, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigFile. -func (in *ConfigFile) DeepCopy() *ConfigFile { - if in == nil { - return nil - } - out := new(ConfigFile) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Environment) DeepCopyInto(out *Environment) { *out = *in out.TypeMeta = in.TypeMeta - in.CapsuleBase.DeepCopyInto(&out.CapsuleBase) + in.Spec.DeepCopyInto(&out.Spec) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Environment. @@ -217,17 +197,46 @@ func (in *EnvironmentVariables) DeepCopy() *EnvironmentVariables { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *File) DeepCopyInto(out *File) { + *out = *in + if in.Bytes != nil { + in, out := &in.Bytes, &out.Bytes + *out = new([]byte) + if **in != nil { + in, out := *in, *out + *out = make([]byte, len(*in)) + copy(*out, *in) + } + } + if in.String != nil { + in, out := &in.String, &out.String + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new File. +func (in *File) DeepCopy() *File { + if in == nil { + return nil + } + out := new(File) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ProjEnvCapsuleBase) DeepCopyInto(out *ProjEnvCapsuleBase) { *out = *in - if in.ConfigFiles != nil { - in, out := &in.ConfigFiles, &out.ConfigFiles - *out = make([]ConfigFile, len(*in)) + if in.Files != nil { + in, out := &in.Files, &out.Files + *out = make([]File, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } - in.EnvironmentVariables.DeepCopyInto(&out.EnvironmentVariables) + in.Env.DeepCopyInto(&out.Env) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjEnvCapsuleBase. @@ -249,7 +258,7 @@ func (in *Project) DeepCopyInto(out *Project) { *out = make([]string, len(*in)) copy(*out, *in) } - in.CapsuleBase.DeepCopyInto(&out.CapsuleBase) + in.Spec.DeepCopyInto(&out.Spec) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Project. diff --git a/pkg/obj/merge.go b/pkg/obj/merge.go index 82fe438a0..6ab8d0c07 100644 --- a/pkg/obj/merge.go +++ b/pkg/obj/merge.go @@ -102,20 +102,20 @@ func convert[T any](obj any) (T, error) { } // nolint:lll -// MergeProjectEnv merges a ProjEnvCapsuleBase into a CapsuleSpecExtension and returns a new object with the merged result +// MergeProjectEnv merges a ProjEnvCapsuleBase into a CapsuleSpec and returns a new object with the merged result // It uses StrategicMergePatch (https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/) -func MergeProjectEnv(patch *platformv1.ProjEnvCapsuleBase, into *platformv1.CapsuleSpecExtension) (*platformv1.CapsuleSpecExtension, error) { +func MergeProjectEnv(patch *platformv1.ProjEnvCapsuleBase, into *platformv1.CapsuleSpec) (*platformv1.CapsuleSpec, error) { return mergeCapsuleSpec(patch, into) } // nolint:lll -// MergeCapsuleSpecExtension merges a CapsuleSpecExtension into another CapsuleSpecExtension and returns a new object with the merged result +// MergeCapsuleSpec merges a CapsuleSpec into another CapsuleSpec and returns a new object with the merged result // It uses StrategicMergePatch (https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/) -func MergeCapsuleSpecExtensions(patch, into *platformv1.CapsuleSpecExtension) (*platformv1.CapsuleSpecExtension, error) { +func MergeCapsuleSpecs(patch, into *platformv1.CapsuleSpec) (*platformv1.CapsuleSpec, error) { return mergeCapsuleSpec(patch, into) } -func mergeCapsuleSpec(patch any, into *platformv1.CapsuleSpecExtension) (*platformv1.CapsuleSpecExtension, error) { +func mergeCapsuleSpec(patch any, into *platformv1.CapsuleSpec) (*platformv1.CapsuleSpec, error) { // It would be possible to do much faster merging by manualling overwriting protobuf fields. // This is tedius to maintain so until it becomes an issue, we use json marshalling to leverage StrategicMergePatch patchBytes, err := json.Marshal(patch) @@ -128,12 +128,12 @@ func mergeCapsuleSpec(patch any, into *platformv1.CapsuleSpecExtension) (*platfo return nil, err } - outBytes, err := strategicpatch.StrategicMergePatch(intoBytes, patchBytes, &v1.CapsuleSpecExtension{}) + outBytes, err := strategicpatch.StrategicMergePatch(intoBytes, patchBytes, &v1.CapsuleSpec{}) if err != nil { return nil, err } - out := &platformv1.CapsuleSpecExtension{} + out := &platformv1.CapsuleSpec{} if err := json.Unmarshal(outBytes, out); err != nil { return nil, err } diff --git a/pkg/obj/merge_test.go b/pkg/obj/merge_test.go index a758e0c35..0d6c37bd2 100644 --- a/pkg/obj/merge_test.go +++ b/pkg/obj/merge_test.go @@ -352,54 +352,54 @@ func Test_mergeCapsuleSpec(t *testing.T) { tests := []struct { name string patch any - into *platformv1.CapsuleSpecExtension - expected *platformv1.CapsuleSpecExtension + into *platformv1.CapsuleSpec + expected *platformv1.CapsuleSpec }{ { name: "empty projEnv base", patch: &platformv1.ProjEnvCapsuleBase{}, - into: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + into: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", }, - expected: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + expected: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", }, }, { name: "projEnv config files", patch: &platformv1.ProjEnvCapsuleBase{ - ConfigFiles: []*platformv1.ConfigFile{{ - Path: "some-path", - Content: []byte{1, 2, 3}, + Files: []*platformv1.File{{ + Path: "some-path", + Bytes: []byte{1, 2, 3}, }}, }, - into: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + into: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", - ConfigFiles: []*platformv1.ConfigFile{ + Files: []*platformv1.File{ { - Path: "some-path", - Content: []byte{5, 6, 7}, + Path: "some-path", + Bytes: []byte{5, 6, 7}, }, { - Path: "some-path2", - Content: []byte{1, 2, 3, 4}, + Path: "some-path2", + Bytes: []byte{1, 2, 3, 4}, }, }, }, - expected: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + expected: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", - ConfigFiles: []*platformv1.ConfigFile{ + Files: []*platformv1.File{ { - Path: "some-path", - Content: []byte{1, 2, 3}, + Path: "some-path", + Bytes: []byte{1, 2, 3}, }, { - Path: "some-path2", - Content: []byte{1, 2, 3, 4}, + Path: "some-path2", + Bytes: []byte{1, 2, 3, 4}, }, }, }, @@ -407,28 +407,28 @@ func Test_mergeCapsuleSpec(t *testing.T) { { name: "projEnv has env vars", patch: &platformv1.ProjEnvCapsuleBase{ - ConfigFiles: []*platformv1.ConfigFile{}, - EnvironmentVariables: &platformv1.EnvironmentVariables{ + Files: []*platformv1.File{}, + Env: &platformv1.EnvironmentVariables{ Direct: map[string]string{ "key1": "value1", "key2": "value2", }, }, }, - into: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + into: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", - EnvironmentVariables: &platformv1.EnvironmentVariables{ + Env: &platformv1.EnvironmentVariables{ Direct: map[string]string{ "key1": "other-value", "key3": "value3", }, }, }, - expected: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + expected: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", - EnvironmentVariables: &platformv1.EnvironmentVariables{ + Env: &platformv1.EnvironmentVariables{ Direct: map[string]string{ "key1": "value1", "key2": "value2", @@ -439,15 +439,15 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, { name: "empty capsule patch", - patch: &platformv1.CapsuleSpecExtension{}, - into: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + patch: &platformv1.CapsuleSpec{}, + into: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", Image: "image", Args: []string{"arg"}, }, - expected: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + expected: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", Image: "image", Args: []string{"arg"}, @@ -455,34 +455,32 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, { name: "capsule patch with simple values", - patch: &platformv1.CapsuleSpecExtension{ - Image: "image", - Command: "command", - Args: []string{"arg1", "arg2"}, - NodeSelector: map[string]string{"key1": "value1"}, - Annotations: map[string]string{"key2": "value2"}, - }, - into: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", + patch: &platformv1.CapsuleSpec{ + Image: "image", + Command: "command", + Args: []string{"arg1", "arg2"}, + Annotations: map[string]string{"key2": "value2"}, + }, + into: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", ApiVersion: "v1", Image: "otherimage", Command: "othercommand", Args: []string{"otherarg"}, Annotations: map[string]string{"key3": "value3"}, }, - expected: &platformv1.CapsuleSpecExtension{ - Kind: "CapsuleSpecExtension", - ApiVersion: "v1", - Image: "image", - Command: "command", - Args: []string{"arg1", "arg2"}, - NodeSelector: map[string]string{"key1": "value1"}, - Annotations: map[string]string{"key2": "value2", "key3": "value3"}, + expected: &platformv1.CapsuleSpec{ + Kind: "CapsuleSpec", + ApiVersion: "v1", + Image: "image", + Command: "command", + Args: []string{"arg1", "arg2"}, + Annotations: map[string]string{"key2": "value2", "key3": "value3"}, }, }, { name: "interface patch", - patch: &platformv1.CapsuleSpecExtension{ + patch: &platformv1.CapsuleSpec{ Interfaces: []*v1alpha2.CapsuleInterface{ { Name: "interface1", @@ -498,7 +496,7 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, }, }, - into: &platformv1.CapsuleSpecExtension{ + into: &platformv1.CapsuleSpec{ Interfaces: []*v1alpha2.CapsuleInterface{ { Name: "interface1", @@ -514,7 +512,7 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, }, }, - expected: &platformv1.CapsuleSpecExtension{ + expected: &platformv1.CapsuleSpec{ Interfaces: []*v1alpha2.CapsuleInterface{ { Name: "interface1", @@ -541,7 +539,7 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, { name: "scale patch", - patch: &platformv1.CapsuleSpecExtension{ + patch: &platformv1.CapsuleSpec{ Scale: &v1alpha2.CapsuleScale{ Horizontal: &v1alpha2.HorizontalScale{ Instances: &v1alpha2.Instances{ @@ -564,7 +562,7 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, }, }, - into: &platformv1.CapsuleSpecExtension{ + into: &platformv1.CapsuleSpec{ Scale: &v1alpha2.CapsuleScale{ Horizontal: &v1alpha2.HorizontalScale{ Instances: &v1alpha2.Instances{ @@ -587,7 +585,7 @@ func Test_mergeCapsuleSpec(t *testing.T) { }, }, }, - expected: &platformv1.CapsuleSpecExtension{ + expected: &platformv1.CapsuleSpec{ Scale: &v1alpha2.CapsuleScale{ Horizontal: &v1alpha2.HorizontalScale{ Instances: &v1alpha2.Instances{ diff --git a/proto/rig/platform/v1/generated.proto b/proto/rig/platform/v1/generated.proto index 17b1743a7..4c61f97dc 100644 --- a/proto/rig/platform/v1/generated.proto +++ b/proto/rig/platform/v1/generated.proto @@ -4,35 +4,36 @@ package platform.v1; import "v1alpha2/generated.proto"; -message CapsuleStar { +message Capsule { string kind = 1; string apiVersion = 2; string name = 3; string project = 4; - CapsuleSpecExtension capsuleBase = 5; - repeated string environments = 6; + CapsuleSpec spec = 5; + map environments = 6; + repeated string environmentRefs = 7; } -message CapsuleSpecExtension { +message CapsuleSpec { string kind = 1; string apiVersion = 2; + map annotations = 11; string image = 3; string command = 4; repeated string args = 5; repeated v1alpha2.CapsuleInterface interfaces = 6; - repeated ConfigFile configFiles = 7; - EnvironmentVariables environmentVariables = 12; + repeated File files = 7; + EnvironmentVariables env = 12; v1alpha2.CapsuleScale scale = 8; - map nodeSelector = 9; repeated v1alpha2.CronJob cronJobs = 10; - map annotations = 11; bool autoAddRigServiceAccounts = 13; } -message ConfigFile { +message File { string path = 1; - bytes content = 2; - bool isSecret = 3; + bool asSecret = 3; + bytes bytes = 4; + string string = 5; } message EnvironmentVariables { @@ -51,7 +52,7 @@ message CapsuleEnvironment { string name = 3; string project = 4; string environment = 5; - CapsuleSpecExtension spec = 6; + CapsuleSpec spec = 6; } message Environment { @@ -60,13 +61,13 @@ message Environment { string name = 3; string namespaceTemplate = 4; string operatorVersion = 5; - string clusterID = 6; - ProjEnvCapsuleBase capsuleBase = 7; + string cluster = 6; + ProjEnvCapsuleBase spec = 7; } message ProjEnvCapsuleBase { - repeated ConfigFile configFiles = 1; - EnvironmentVariables environmentVariables = 2; + repeated File files = 1; + EnvironmentVariables env = 2; } message Project { @@ -74,5 +75,5 @@ message Project { string apiVersion = 2; string name = 3; repeated string environments = 4; - ProjEnvCapsuleBase capsuleBase = 5; + ProjEnvCapsuleBase spec = 5; }