Skip to content

Commit

Permalink
fix: make spec.name optional
Browse files Browse the repository at this point in the history
By default use the k8s resource name and allow to be overriden by the
`spec.name` if any
  • Loading branch information
eliecharra committed Jun 17, 2024
1 parent ac934fb commit 3403b03
Show file tree
Hide file tree
Showing 30 changed files with 235 additions and 181 deletions.
10 changes: 8 additions & 2 deletions api/v1beta1/context_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ type Attachment struct {
// 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)
type ContextSpec struct {
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
Name *string `json:"name,omitempty"`
// +kubebuilder:validation:MinLength=1
SpaceId *string `json:"spaceId,omitempty"`
// +kubebuilder:validation:MinLength=1
Expand Down Expand Up @@ -104,6 +103,13 @@ type Context struct {
Status ContextStatus `json:"status,omitempty"`
}

func (c *Context) Name() string {
if c.Spec.Name != nil {
return *c.Spec.Name
}
return c.ObjectMeta.Name
}

func (c *Context) SetContext(context *models.Context) {
if context.Id != "" {
c.Status.Id = context.Id
Expand Down
10 changes: 8 additions & 2 deletions api/v1beta1/policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
// +kubebuilder:validation:XValidation:rule="(has(self.spaceName) != has(self.spaceId)) || (!has(self.spaceName) && !has(self.spaceId))",message="only one of spaceName or spaceId can be set"
type PolicySpec struct {
// Name of the policy - should be unique in one account
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
Name *string `json:"name,omitempty"`
// Body of the policy
// +kubebuilder:validation:MinLength=1
Body string `json:"body"`
Expand Down Expand Up @@ -66,6 +65,13 @@ type Policy struct {
Status PolicyStatus `json:"status,omitempty"`
}

func (p *Policy) Name() string {
if p.Spec.Name != nil {
return *p.Spec.Name
}
return p.ObjectMeta.Name
}

func (p *Policy) SetPolicy(policy models.Policy) {
p.Status.Id = policy.Id
}
Expand Down
12 changes: 9 additions & 3 deletions api/v1beta1/space_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import (
// SpaceSpec defines the desired state of space
type SpaceSpec struct {
// +kubebuilder:validation:MinLength=1
ParentSpace string `json:"parentSpace"`
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
ParentSpace string `json:"parentSpace"`
Name *string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
InheritEntities bool `json:"inheritEntities,omitempty"`
Labels *[]string `json:"labels,omitempty"`
Expand All @@ -45,6 +44,13 @@ type Space struct {
Status SpaceStatus `json:"status,omitempty"`
}

func (s *Space) Name() string {
if s.Spec.Name != nil {
return *s.Spec.Name
}
return s.ObjectMeta.Name
}

func (s *Space) Ready() bool {
return s.Status.Id != ""
}
Expand Down
10 changes: 8 additions & 2 deletions api/v1beta1/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ type StackSpec struct {
// +kubebuilder:validation:MinLength=1
CommitSHA *string `json:"commitSHA,omitempty"`

// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
Name *string `json:"name,omitempty"`
SpaceName *string `json:"spaceName,omitempty"`
SpaceId *string `json:"spaceId,omitempty"`
AdditionalProjectGlobs *[]string `json:"additionalProjectGlobs,omitempty"`
Expand Down Expand Up @@ -139,6 +138,13 @@ type Stack struct {
Status StackStatus `json:"status,omitempty"`
}

func (s *Stack) Name() string {
if s.Spec.Name != nil {
return *s.Spec.Name
}
return s.ObjectMeta.Name
}

func (s *Stack) Ready() bool {
return s.Status.Id != ""
}
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions config/crd/bases/app.spacelift.io_contexts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,13 @@ spec:
rule: has(self.valueFromSecret) != has(self.value)
type: array
name:
minLength: 1
type: string
space:
minLength: 1
type: string
spaceId:
minLength: 1
type: string
required:
- name
type: object
x-kubernetes-validations:
- message: only one of space or spaceId should be set
Expand Down
2 changes: 0 additions & 2 deletions config/crd/bases/app.spacelift.io_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ spec:
type: array
name:
description: Name of the policy - should be unique in one account
minLength: 1
type: string
spaceId:
description: SpaceId is ID (slug) of the space the policy is in
Expand All @@ -82,7 +81,6 @@ spec:
type: string
required:
- body
- name
- type
type: object
x-kubernetes-validations:
Expand Down
2 changes: 0 additions & 2 deletions config/crd/bases/app.spacelift.io_spaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ spec:
type: string
type: array
name:
minLength: 1
type: string
parentSpace:
minLength: 1
type: string
required:
- name
- parentSpace
type: object
status:
Expand Down
2 changes: 0 additions & 2 deletions config/crd/bases/app.spacelift.io_stacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ spec:
description: In our API managesStateFile is not part of StackInput
type: boolean
name:
minLength: 1
type: string
projectRoot:
type: string
Expand Down Expand Up @@ -221,7 +220,6 @@ spec:
workerPool:
type: string
required:
- name
- repository
type: object
x-kubernetes-validations:
Expand Down
Loading

0 comments on commit 3403b03

Please sign in to comment.