diff --git a/api/v1beta1/context_types.go b/api/v1beta1/context_types.go index e34b48c..24dea85 100644 --- a/api/v1beta1/context_types.go +++ b/api/v1beta1/context_types.go @@ -58,25 +58,25 @@ type Hooks struct { BeforePlan []string `json:"beforePlan,omitempty"` } -// +kubebuilder:validation:XValidation:message=only one of stack or stackId or moduleId should be set,rule=has(self.stack) != has(self.stackId) != has(self.moduleId) +// +kubebuilder:validation:XValidation:message=only one of stackName or stackId or moduleId should be set,rule=has(self.stackName) != has(self.stackId) != has(self.moduleId) type Attachment struct { // +kubebuilder:validation:MinLength=1 ModuleId *string `json:"moduleId,omitempty"` // +kubebuilder:validation:MinLength=1 StackId *string `json:"stackId,omitempty"` // +kubebuilder:validation:MinLength=1 - Stack *string `json:"stack,omitempty"` - Priority *int `json:"priority,omitempty"` + StackName *string `json:"stackName,omitempty"` + Priority *int `json:"priority,omitempty"` } // ContextSpec defines the desired state of Context -// +kubebuilder:validation:XValidation:message=only one of space or spaceId should be set,rule=has(self.spaceId) != has(self.space) +// +kubebuilder:validation:XValidation:message=only one of spaceName or spaceId should be set,rule=has(self.spaceId) != has(self.spaceName) type ContextSpec struct { Name *string `json:"name,omitempty"` // +kubebuilder:validation:MinLength=1 SpaceId *string `json:"spaceId,omitempty"` // +kubebuilder:validation:MinLength=1 - Space *string `json:"space,omitempty"` + SpaceName *string `json:"spaceName,omitempty"` Description *string `json:"description,omitempty"` Labels []string `json:"labels,omitempty"` diff --git a/api/v1beta1/policy_types.go b/api/v1beta1/policy_types.go index db66126..bb6e21d 100644 --- a/api/v1beta1/policy_types.go +++ b/api/v1beta1/policy_types.go @@ -44,7 +44,7 @@ type PolicySpec struct { // SpaceId is ID (slug) of the space the policy is in SpaceId *string `json:"spaceId,omitempty"` - AttachedStacksNames []string `json:"attachedStacks,omitempty"` + AttachedStacksNames []string `json:"attachedStacksNames,omitempty"` AttachedStacksIds []string `json:"attachedStacksIds,omitempty"` } diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index f1aa377..4a0a4d9 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -68,8 +68,8 @@ func (in *Attachment) DeepCopyInto(out *Attachment) { *out = new(string) **out = **in } - if in.Stack != nil { - in, out := &in.Stack, &out.Stack + if in.StackName != nil { + in, out := &in.StackName, &out.StackName *out = new(string) **out = **in } @@ -202,8 +202,8 @@ func (in *ContextSpec) DeepCopyInto(out *ContextSpec) { *out = new(string) **out = **in } - if in.Space != nil { - in, out := &in.Space, &out.Space + if in.SpaceName != nil { + in, out := &in.SpaceName, &out.SpaceName *out = new(string) **out = **in } diff --git a/config/crd/bases/app.spacelift.io_contexts.yaml b/config/crd/bases/app.spacelift.io_contexts.yaml index 63af7d7..ad63602 100644 --- a/config/crd/bases/app.spacelift.io_contexts.yaml +++ b/config/crd/bases/app.spacelift.io_contexts.yaml @@ -42,16 +42,17 @@ spec: type: string priority: type: integer - stack: + stackId: minLength: 1 type: string - stackId: + stackName: minLength: 1 type: string type: object x-kubernetes-validations: - - message: only one of stack or stackId or moduleId should be set - rule: has(self.stack) != has(self.stackId) != has(self.moduleId) + - message: only one of stackName or stackId or moduleId should be + set + rule: has(self.stackName) != has(self.stackId) != has(self.moduleId) type: array description: type: string @@ -185,16 +186,16 @@ spec: type: array name: type: string - space: + spaceId: minLength: 1 type: string - spaceId: + spaceName: minLength: 1 type: string type: object x-kubernetes-validations: - - message: only one of space or spaceId should be set - rule: has(self.spaceId) != has(self.space) + - message: only one of spaceName or spaceId should be set + rule: has(self.spaceId) != has(self.spaceName) status: description: ContextStatus defines the observed state of Context properties: diff --git a/config/crd/bases/app.spacelift.io_policies.yaml b/config/crd/bases/app.spacelift.io_policies.yaml index db3e42b..fabfe7c 100644 --- a/config/crd/bases/app.spacelift.io_policies.yaml +++ b/config/crd/bases/app.spacelift.io_policies.yaml @@ -34,11 +34,11 @@ spec: spec: description: PolicySpec defines the desired state of Policy properties: - attachedStacks: + attachedStacksIds: items: type: string type: array - attachedStacksIds: + attachedStacksNames: items: type: string type: array diff --git a/internal/controller/context_controller.go b/internal/controller/context_controller.go index 220b017..d932b4d 100644 --- a/internal/controller/context_controller.go +++ b/internal/controller/context_controller.go @@ -76,9 +76,9 @@ func (r *ContextReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct log.IntoContext(ctx, logger) // A context should always be linked to a valid space - if context.Spec.Space != nil { - logger := logger.WithValues(logging.SpaceName, *context.Spec.Space) - space, err := r.SpaceRepository.Get(ctx, types.NamespacedName{Namespace: context.Namespace, Name: *context.Spec.Space}) + if context.Spec.SpaceName != nil { + logger := logger.WithValues(logging.SpaceName, *context.Spec.SpaceName) + space, err := r.SpaceRepository.Get(ctx, types.NamespacedName{Namespace: context.Namespace, Name: *context.Spec.SpaceName}) if err != nil { if k8sErrors.IsNotFound(err) { logger.V(logging.Level4).Info("Unable to find space for context, will retry in 10 seconds") @@ -107,12 +107,12 @@ func (r *ContextReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct // For all stack attachment, ensure that all stacks are ready for i, attachment := range context.Spec.Attachments { - if attachment.Stack != nil { - logger := logger.WithValues(logging.StackName, *attachment.Stack) + if attachment.StackName != nil { + logger := logger.WithValues(logging.StackName, *attachment.StackName) // Test if stack exists and is ready stack, err := r.StackRepository.Get(ctx, types.NamespacedName{ Namespace: context.Namespace, - Name: *attachment.Stack, + Name: *attachment.StackName, }) if err != nil { if k8sErrors.IsNotFound(err) { diff --git a/internal/controller/context_controller_test.go b/internal/controller/context_controller_test.go index ffa9543..dbf305a 100644 --- a/internal/controller/context_controller_test.go +++ b/internal/controller/context_controller_test.go @@ -78,23 +78,23 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }{ { Spec: v1beta1.ContextSpec{}, - Name: "empty spec, missing space or spaceId", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec: Invalid value: "object": only one of space or spaceId should be set`, + Name: "empty spec, missing spaceName or spaceId", + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec: Invalid value: "object": only one of spaceName or spaceId should be set`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), - SpaceId: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), + SpaceId: utils.AddressOf("foobar"), }, - Name: "both space and spaceId are set", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec: Invalid value: "object": only one of space or spaceId should be set`, + Name: "both spaceName and spaceId are set", + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec: Invalid value: "object": only one of spaceName or spaceId should be set`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf(""), + SpaceName: utils.AddressOf(""), }, Name: "space empty string", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.space: Invalid value: "": spec.space in body should be at least 1 chars long`, + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.spaceName: Invalid value: "": spec.spaceName in body should be at least 1 chars long`, }, { Spec: v1beta1.ContextSpec{ @@ -105,59 +105,59 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{}}, }, Name: "empty attachment", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stack or stackId or moduleId should be set`, + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stackName or stackId or moduleId should be set`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{ - Stack: utils.AddressOf("foobar"), - StackId: utils.AddressOf("foobar"), + StackName: utils.AddressOf("foobar"), + StackId: utils.AddressOf("foobar"), }}, }, Name: "attachment with both stack and stackId", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stack or stackId or moduleId should be set`, + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stackName or stackId or moduleId should be set`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{ ModuleId: utils.AddressOf("foobar"), StackId: utils.AddressOf("foobar"), }}, }, Name: "attachment with both stackId and moduleId", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stack or stackId or moduleId should be set`, + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stackName or stackId or moduleId should be set`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{ - Stack: utils.AddressOf("foobar"), - ModuleId: utils.AddressOf("foobar"), + StackName: utils.AddressOf("foobar"), + ModuleId: utils.AddressOf("foobar"), }}, }, Name: "attachment with both stack and moduleId", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stack or stackId or moduleId should be set`, + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0]: Invalid value: "object": only one of stackName or stackId or moduleId should be set`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{ - Stack: utils.AddressOf(""), + StackName: utils.AddressOf(""), }}, }, - Name: "attachment stack empty", - ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0].stack: Invalid value: "": spec.attachments[0].stack in body should be at least 1 chars long`, + Name: "attachment stackName empty", + ExpectedErr: `Context.app.spacelift.io "invalid-context" is invalid: spec.attachments[0].stackName: Invalid value: "": spec.attachments[0].stackName in body should be at least 1 chars long`, }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{ StackId: utils.AddressOf(""), }}, @@ -167,7 +167,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Attachments: []v1beta1.Attachment{{ ModuleId: utils.AddressOf(""), }}, @@ -177,7 +177,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Environment: []v1beta1.Environment{ { Id: "", @@ -190,7 +190,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), Environment: []v1beta1.Environment{ { Id: "test", @@ -204,7 +204,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), MountedFiles: []v1beta1.MountedFile{ { Id: "", @@ -217,7 +217,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_InvalidSpec() { }, { Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("foobar"), + SpaceName: utils.AddressOf("foobar"), MountedFiles: []v1beta1.MountedFile{ { Id: "test", @@ -288,7 +288,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_OK_SpaceNotReady() { Namespace: "default", }, Spec: v1beta1.ContextSpec{ - Space: utils.AddressOf("test-space"), + SpaceName: utils.AddressOf("test-space"), }, } s.Logs.TakeAll() @@ -361,7 +361,7 @@ func (s *ContextControllerTestSuite) TestContextCreation_OK_AttachedStackNotRead SpaceId: utils.AddressOf("test-space"), Attachments: []v1beta1.Attachment{ { - Stack: utils.AddressOf("test-stack"), + StackName: utils.AddressOf("test-stack"), }, }, },