Skip to content

Commit

Permalink
✨ Add Capsule-Extensions to Pipeline configuration (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersjohnsen authored Sep 12, 2024
1 parent 02d4b54 commit 330e9d0
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/docs/api/config/v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ _Appears in:_
| `serviceMonitorStep` _[CapsuleStep](#capsulestep)_ | How to handle the service monitor step of capsules in the cluster. If left empty, no service monitors will be created. rigdev.service_monitor plugin spawns a Prometheus ServiceMonitor per capsule for use with a Prometheus Operator stack. |
| `steps` _[Step](#step) array_ | Steps to perform as part of running the operator. |
| `customPlugins` _[CustomPlugin](#customplugin) array_ | CustomPlugins enables custom plugins to be injected into the operator. The plugins injected here can then be referenced in 'steps' |
| `capsuleExtensions` _object (keys:string, values:[CapsuleStep](#capsulestep))_ | CapsuleExtensions supported by the Operator. Each extension supported should be configured in the map, with an additional plugin name. |


### PlatformConfig
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/config/v1alpha1/operator_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type Pipeline struct {
// CustomPlugins enables custom plugins to be injected into the
// operator. The plugins injected here can then be referenced in 'steps'
CustomPlugins []CustomPlugin `json:"customPlugins,omitempty"`
// CapsuleExtensions supported by the Operator. Each extension supported
// should be configured in the map, with an additional plugin name.
CapsuleExtensions map[string]CapsuleStep `json:"capsuleExtensions,omitempty"`
}

type CapsuleStep struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/config/v1alpha1/zz_generated.deepcopy.go

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

73 changes: 73 additions & 0 deletions pkg/service/pipeline/capsule_extension_step.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package pipeline

import (
"context"

"github.com/rigdev/rig/pkg/api/config/v1alpha1"
"github.com/rigdev/rig/pkg/errors"
"github.com/rigdev/rig/pkg/pipeline"
"github.com/rigdev/rig/pkg/uuid"
)

type CapsuleExtensionStep struct {
name string
step pipeline.Step[pipeline.CapsuleRequest]
}

func NewCapsuleExtensionStep(name string, step pipeline.Step[pipeline.CapsuleRequest]) *CapsuleExtensionStep {
return &CapsuleExtensionStep{
name: name,
step: step,
}
}

func (s *CapsuleExtensionStep) Apply(ctx context.Context, req pipeline.CapsuleRequest, opts pipeline.Options) error {
if _, ok := req.Capsule().Spec.Extensions[s.name]; ok {
return s.step.Apply(ctx, req, opts)
}

return nil
}

func (s *CapsuleExtensionStep) WatchObjectStatus(
ctx context.Context, namespace, capsule string, callback pipeline.ObjectStatusCallback,
) error {
// TODO: We want to opt out if not relevant for this capsule.
return s.step.WatchObjectStatus(ctx, namespace, capsule, callback)
}

func (s *CapsuleExtensionStep) PluginIDs() []uuid.UUID {
return s.step.PluginIDs()
}

type CapsuleExtensionValidationStep struct {
cfg *v1alpha1.OperatorConfig
}

func NewCapsuleExtensionValidationStep(cfg *v1alpha1.OperatorConfig) *CapsuleExtensionValidationStep {
return &CapsuleExtensionValidationStep{
cfg: cfg,
}
}

func (s *CapsuleExtensionValidationStep) Apply(
_ context.Context, req pipeline.CapsuleRequest, _ pipeline.Options,
) error {
for name := range req.Capsule().Spec.Extensions {
if _, ok := s.cfg.Pipeline.CapsuleExtensions[name]; !ok {
return errors.UnimplementedErrorf("capsule extension '%s' not supported by cluster", name)
}
}

return nil
}

func (s *CapsuleExtensionValidationStep) WatchObjectStatus(
_ context.Context, _, _ string, _ pipeline.ObjectStatusCallback,
) error {
return nil
}

func (s *CapsuleExtensionValidationStep) PluginIDs() []uuid.UUID {
return nil
}
12 changes: 12 additions & 0 deletions pkg/service/pipeline/default_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ func GetDefaultPipelineSteps(
steps = append(steps, serviceMonitorStep)
}

steps = append(steps, NewCapsuleExtensionValidationStep(cfg))
for name, capsuleStep := range cfg.Pipeline.CapsuleExtensions {
if capsuleStep.Plugin != "" {
step, err := NewCapsulePluginStep(execCtx, capsuleStep.Plugin, capsuleStep.Config, pluginManager, logger, false)
if err != nil {
return nil, err
}

steps = append(steps, NewCapsuleExtensionStep(name, step))
}
}

return steps, nil
}

Expand Down

0 comments on commit 330e9d0

Please sign in to comment.