Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): stacks configuration handling and observability provider readonly mode #1271

Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ spec:
version:
description: Version the semver of the tool you wish to use
type: string
required:
- version
type: object
cron:
description: Configuration for cron generation of stack runs
Expand Down Expand Up @@ -8685,7 +8683,6 @@ spec:
type: string
required:
- clusterRef
- configuration
- git
- repositoryRef
- type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ spec:
- NEWRELIC
type: string
required:
- credentials
- name
- type
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ spec:
version:
description: Version the semver of the tool you wish to use
type: string
required:
- version
type: object
description:
description: Description can be used to describe this StackDefinition.
Expand Down Expand Up @@ -136,8 +134,6 @@ spec:
- stage
type: object
type: array
required:
- configuration
type: object
status:
properties:
Expand Down
12 changes: 6 additions & 6 deletions go/controller/api/v1alpha1/infrastructurestack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type InfrastructureStackSpec struct {
JobSpec *JobSpec `json:"jobSpec,omitempty"`

// Configuration version/image config for the tool you're using
// +kubebuilder:validation:Required
Configuration StackConfiguration `json:"configuration"`
// +kubebuilder:validation:Optional
Configuration *StackConfiguration `json:"configuration,omitempty"`

// Configuration for cron generation of stack runs
// +kubebuilder:validation:Optional
Expand Down Expand Up @@ -143,15 +143,15 @@ type StackConfiguration struct {
// +kubebuilder:validation:Optional
Image *string `json:"image,omitempty"`
// Version the semver of the tool you wish to use
// +kubebuilder:validation:Required
Version string `json:"version"`
// Hooks to run at various stages of the stack run
// +kubebuilder:validation:Optional
Hooks []*StackHook `json:"hooks,omitempty"`
Version *string `json:"version,omitempty"`
// Tag is the docker image tag you wish to use
// if you're customizing the version
// +kubebuilder:validation:Optional
Tag *string `json:"tag,omitempty"`
// Hooks to run at various stages of the stack run
// +kubebuilder:validation:Optional
Hooks []*StackHook `json:"hooks,omitempty"`
}

type StackCron struct {
Expand Down
18 changes: 13 additions & 5 deletions go/controller/api/v1alpha1/observabilityprovider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ type ObservabilityProvider struct {
Status Status `json:"status,omitempty"`
}

func (in *ObservabilityProvider) ConsoleName() string {
if in.Spec.Name != nil && len(*in.Spec.Name) > 0 {
return *in.Spec.Name
}

return in.Name
}

func (in *ObservabilityProvider) SetCondition(condition metav1.Condition) {
meta.SetStatusCondition(&in.Status.Conditions, condition)
}
Expand All @@ -54,25 +62,25 @@ func (in *ObservabilityProvider) Diff(hasher Hasher) (changed bool, sha string,

func (in *ObservabilityProvider) Attributes(credentials client.ObservabilityProviderCredentialsAttributes) client.ObservabilityProviderAttributes {
return client.ObservabilityProviderAttributes{
Name: in.Spec.Name,
Name: in.ConsoleName(),
Type: in.Spec.Type,
Credentials: credentials,
}
}

type ObservabilityProviderSpec struct {
// Name of the ObservabilityProvider in the Console API.
// +kubebuilder:validation:Required
Name string `json:"name"`
// +kubebuilder:validation:Optional
Name *string `json:"name,omitempty"`

// Type of the ObservabilityProvider.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=DATADOG;NEWRELIC
Type client.ObservabilityProviderType `json:"type"`

// Credentials to access the configured provider Type.
// +kubebuilder:validation:Required
Credentials ObservabilityProviderCredentials `json:"credentials"`
// +kubebuilder:validation:Optional
Credentials *ObservabilityProviderCredentials `json:"credentials,omitempty"`
}

type ObservabilityProviderCredentials struct {
Expand Down
36 changes: 21 additions & 15 deletions go/controller/api/v1alpha1/stackdefinition_types.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package v1alpha1

import (
console "github.com/pluralsh/console/go/client"
"github.com/pluralsh/polly/algorithms"
"github.com/samber/lo"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

console "github.com/pluralsh/console/go/client"
)

func init() {
Expand Down Expand Up @@ -55,12 +56,23 @@ func (in *StackDefinition) Diff(hasher Hasher) (changed bool, sha string, err er
}

func (in *StackDefinition) Attributes() console.StackDefinitionAttributes {
return console.StackDefinitionAttributes{
result := console.StackDefinitionAttributes{
Name: in.StackName(),
Description: in.Spec.Description,
Configuration: &console.StackConfigurationAttributes{
Steps: algorithms.Map(in.Spec.Steps, func(s CustomRunStep) *console.CustomStepAttributes {
return &console.CustomStepAttributes{
Stage: &s.Stage,
Cmd: s.Cmd,
Args: lo.ToSlicePtr(s.Args),
RequireApproval: s.RequireApproval,
}
}),
}

if in.Spec.Configuration != nil {
result.Configuration = &console.StackConfigurationAttributes{
Image: in.Spec.Configuration.Image,
Version: &in.Spec.Configuration.Version,
Version: in.Spec.Configuration.Version,
Tag: in.Spec.Configuration.Tag,
Hooks: algorithms.Map(in.Spec.Configuration.Hooks, func(h *StackHook) *console.StackHookAttributes {
return &console.StackHookAttributes{
Expand All @@ -69,16 +81,10 @@ func (in *StackDefinition) Attributes() console.StackDefinitionAttributes {
AfterStage: h.AfterStage,
}
}),
},
Steps: algorithms.Map(in.Spec.Steps, func(s CustomRunStep) *console.CustomStepAttributes {
return &console.CustomStepAttributes{
Stage: &s.Stage,
Cmd: s.Cmd,
Args: lo.ToSlicePtr(s.Args),
RequireApproval: s.RequireApproval,
}
}),
}
}

return result
}

// StackDefinitionSpec defines the desired state of StackDefinition
Expand All @@ -99,8 +105,8 @@ type StackDefinitionSpec struct {

// Configuration allows modifying the StackDefinition environment
// and execution.
// +kubebuilder:validation:Required
Configuration StackConfiguration `json:"configuration"`
// +kubebuilder:validation:Optional
Configuration *StackConfiguration `json:"configuration,omitempty"`
}

type CustomRunStep struct {
Expand Down
38 changes: 30 additions & 8 deletions go/controller/api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ spec:
version:
description: Version the semver of the tool you wish to use
type: string
required:
- version
type: object
cron:
description: Configuration for cron generation of stack runs
Expand Down Expand Up @@ -8685,7 +8683,6 @@ spec:
type: string
required:
- clusterRef
- configuration
- git
- repositoryRef
- type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ spec:
- NEWRELIC
type: string
required:
- credentials
- name
- type
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ spec:
version:
description: Version the semver of the tool you wish to use
type: string
required:
- version
type: object
description:
description: Description can be used to describe this StackDefinition.
Expand Down Expand Up @@ -136,8 +134,6 @@ spec:
- stage
type: object
type: array
required:
- configuration
type: object
status:
properties:
Expand Down
Loading
Loading