Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 330e9d0

Browse files
✨ Add Capsule-Extensions to Pipeline configuration (#1208)
1 parent 02d4b54 commit 330e9d0

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

docs/docs/api/config/v1alpha1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ _Appears in:_
608608
| `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. |
609609
| `steps` _[Step](#step) array_ | Steps to perform as part of running the operator. |
610610
| `customPlugins` _[CustomPlugin](#customplugin) array_ | CustomPlugins enables custom plugins to be injected into the operator. The plugins injected here can then be referenced in 'steps' |
611+
| `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. |
611612

612613

613614
### PlatformConfig

pkg/api/config/v1alpha1/operator_config_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type Pipeline struct {
5959
// CustomPlugins enables custom plugins to be injected into the
6060
// operator. The plugins injected here can then be referenced in 'steps'
6161
CustomPlugins []CustomPlugin `json:"customPlugins,omitempty"`
62+
// CapsuleExtensions supported by the Operator. Each extension supported
63+
// should be configured in the map, with an additional plugin name.
64+
CapsuleExtensions map[string]CapsuleStep `json:"capsuleExtensions,omitempty"`
6265
}
6366

6467
type CapsuleStep struct {

pkg/api/config/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package pipeline
2+
3+
import (
4+
"context"
5+
6+
"github.com/rigdev/rig/pkg/api/config/v1alpha1"
7+
"github.com/rigdev/rig/pkg/errors"
8+
"github.com/rigdev/rig/pkg/pipeline"
9+
"github.com/rigdev/rig/pkg/uuid"
10+
)
11+
12+
type CapsuleExtensionStep struct {
13+
name string
14+
step pipeline.Step[pipeline.CapsuleRequest]
15+
}
16+
17+
func NewCapsuleExtensionStep(name string, step pipeline.Step[pipeline.CapsuleRequest]) *CapsuleExtensionStep {
18+
return &CapsuleExtensionStep{
19+
name: name,
20+
step: step,
21+
}
22+
}
23+
24+
func (s *CapsuleExtensionStep) Apply(ctx context.Context, req pipeline.CapsuleRequest, opts pipeline.Options) error {
25+
if _, ok := req.Capsule().Spec.Extensions[s.name]; ok {
26+
return s.step.Apply(ctx, req, opts)
27+
}
28+
29+
return nil
30+
}
31+
32+
func (s *CapsuleExtensionStep) WatchObjectStatus(
33+
ctx context.Context, namespace, capsule string, callback pipeline.ObjectStatusCallback,
34+
) error {
35+
// TODO: We want to opt out if not relevant for this capsule.
36+
return s.step.WatchObjectStatus(ctx, namespace, capsule, callback)
37+
}
38+
39+
func (s *CapsuleExtensionStep) PluginIDs() []uuid.UUID {
40+
return s.step.PluginIDs()
41+
}
42+
43+
type CapsuleExtensionValidationStep struct {
44+
cfg *v1alpha1.OperatorConfig
45+
}
46+
47+
func NewCapsuleExtensionValidationStep(cfg *v1alpha1.OperatorConfig) *CapsuleExtensionValidationStep {
48+
return &CapsuleExtensionValidationStep{
49+
cfg: cfg,
50+
}
51+
}
52+
53+
func (s *CapsuleExtensionValidationStep) Apply(
54+
_ context.Context, req pipeline.CapsuleRequest, _ pipeline.Options,
55+
) error {
56+
for name := range req.Capsule().Spec.Extensions {
57+
if _, ok := s.cfg.Pipeline.CapsuleExtensions[name]; !ok {
58+
return errors.UnimplementedErrorf("capsule extension '%s' not supported by cluster", name)
59+
}
60+
}
61+
62+
return nil
63+
}
64+
65+
func (s *CapsuleExtensionValidationStep) WatchObjectStatus(
66+
_ context.Context, _, _ string, _ pipeline.ObjectStatusCallback,
67+
) error {
68+
return nil
69+
}
70+
71+
func (s *CapsuleExtensionValidationStep) PluginIDs() []uuid.UUID {
72+
return nil
73+
}

pkg/service/pipeline/default_pipeline.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ func GetDefaultPipelineSteps(
145145
steps = append(steps, serviceMonitorStep)
146146
}
147147

148+
steps = append(steps, NewCapsuleExtensionValidationStep(cfg))
149+
for name, capsuleStep := range cfg.Pipeline.CapsuleExtensions {
150+
if capsuleStep.Plugin != "" {
151+
step, err := NewCapsulePluginStep(execCtx, capsuleStep.Plugin, capsuleStep.Config, pluginManager, logger, false)
152+
if err != nil {
153+
return nil, err
154+
}
155+
156+
steps = append(steps, NewCapsuleExtensionStep(name, step))
157+
}
158+
}
159+
148160
return steps, nil
149161
}
150162

0 commit comments

Comments
 (0)