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

✨ Add Extensions to the capsule types #1202

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
425 changes: 217 additions & 208 deletions cmd/rig-proto-gen/main.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cmd/rig/cmd/capsule/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (c *Cmd) getChanges(cmd *cobra.Command, args []string) ([]*capsule.Change,
removeAnnotations != nil ||
cmd.Flag("replicas").Changed ||
configFiles != nil ||
configFileRefs != nil ||
removeConfigFiles != nil ||
networkInterfaces != nil ||
removeNetworkInterfaces != nil {
Expand All @@ -209,7 +210,7 @@ func (c *Cmd) getChanges(cmd *cobra.Command, args []string) ([]*capsule.Change,
}
spec, err := v1.YAMLToCapsuleProto(bytes)
if err != nil {
return nil, "", "", "", err
return nil, "", "", "", fmt.Errorf("oof: %s", err)
}
return []*capsule.Change{{
Field: &capsule.Change_Spec{
Expand Down
3 changes: 3 additions & 0 deletions deploy/charts/rig-operator/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ spec:
type: object
type: array
type: object
extensions:
type: object
x-kubernetes-preserve-unknown-fields: true
files:
description: Files is a list of files to mount in the container. These
can either be based on ConfigMaps or Secrets.
Expand Down
17 changes: 17 additions & 0 deletions docs/docs/api/platform-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,7 @@ A reference to a kubernetes object.
| scale | [Scale](#platform-v1-Scale) | | |
| cronJobs | [CronJob](#platform-v1-CronJob) | repeated | |
| autoAddRigServiceAccounts | [bool](#bool) | | |
| extensions | [CapsuleSpec.ExtensionsEntry](#platform-v1-CapsuleSpec-ExtensionsEntry) | repeated | |



Expand All @@ -1702,6 +1703,22 @@ A reference to a kubernetes object.



<a name="platform-v1-CapsuleSpec-ExtensionsEntry"></a>

### CapsuleSpec.ExtensionsEntry



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [string](#string) | | |
| value | [google.protobuf.Struct](#google-protobuf-Struct) | | |






<a name="platform-v1-CronJob"></a>

### CronJob
Expand Down
1 change: 1 addition & 0 deletions docs/docs/api/platformv1.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ _Appears in:_
| `scale` _[Scale](#scale)_ | Scale specifies the scaling of the Capsule. |
| `cronJobs` _[CronJob](#cronjob) array_ | |
| `autoAddRigServiceAccounts` _boolean_ | TODO Move to plugin |
| `extensions` _object (keys:string, values:RawMessage)_ | Extensions json.RawMessage `json:"extensions,omitempty" protobuf:"14"` |


### CronJob
Expand Down
1 change: 1 addition & 0 deletions docs/docs/api/v1alpha2.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _Appears in:_
| `nodeSelector` _object (keys:string, values:string)_ | NodeSelector is a selector for what nodes the Capsule should live on. |
| `env` _[Env](#env)_ | Env specifies configuration for how the container should obtain environment variables. |
| `cronJobs` _[CronJob](#cronjob) array_ | |
| `extensions` _object (keys:string, values:RawMessage)_ | |


### CronJob
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/platform/v1/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func YAMLToCapsuleSetProto(bytes []byte) (*platformv1.CapsuleSet, error) {

func YAMLToSpecProto[T interface{ GetKind() string }](bs []byte, o T, expectedKind string) error {
if err := yaml.Unmarshal(bs, o, yaml.DisallowUnknownFields); err != nil {
return err
return fmt.Errorf("unmarshal: %s", err)
}
if o.GetKind() != "" && o.GetKind() != expectedKind {
return fmt.Errorf("kind was %s, not the expected %s", o.GetKind(), expectedKind)
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package v1

import (
"encoding/json"
"maps"
"slices"

Expand Down Expand Up @@ -137,6 +138,12 @@ type CapsuleSpec struct {

// TODO Move to plugin
AutoAddRigServiceAccounts bool `json:"autoAddRigServiceAccounts" protobuf:"13"`

// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Type=object
// Extensions json.RawMessage `json:"extensions,omitempty" protobuf:"14"`
Extentions map[string]json.RawMessage `json:"extensions,omitempty" protobuf:"14"`
}

// EnvironmentVariables defines the environment variables injected into a Capsule.
Expand Down
17 changes: 17 additions & 0 deletions pkg/api/platform/v1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions pkg/api/v1alpha2/capsule_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha2

import (
"encoding/json"

autoscalingv2 "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -42,6 +44,11 @@ type CapsuleSpec struct {
Env Env `json:"env,omitempty"`

CronJobs []CronJob `json:"cronJobs,omitempty"`

// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Type=object
Extensions map[string]json.RawMessage `json:"extensions,omitempty"`
}

type CronJob struct {
Expand Down
17 changes: 17 additions & 0 deletions pkg/api/v1alpha2/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions proto/rig/platform/v1/generated.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

package platform.v1;

import "google/protobuf/struct.proto";
import "k8s.io/api/autoscaling/v2/generated.proto";

message CapsuleSet {
Expand All @@ -27,6 +28,7 @@ message CapsuleSpec {
Scale scale = 8;
repeated CronJob cronJobs = 10;
bool autoAddRigServiceAccounts = 13;
map<string, google.protobuf.Struct> extensions = 14;
}

message CapsuleInterface {
Expand Down
15 changes: 15 additions & 0 deletions scripts/crdcopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
s = "\n versions:\n"

with open("deploy/charts/rig-operator/templates/crd.yaml") as f:
helm_data = f.read()
helm_idx = helm_data.find(s) + len(s)
helm_data = helm_data[:helm_idx]

with open("deploy/kustomize/crd/bases/rig.dev_capsules.yaml") as f:
crd_data = f.read()
crd_idx = crd_data.find(s) + len(s)
crd_data = crd_data[crd_idx:]

result = helm_data + crd_data + "{{- end }}\n"
with open("deploy/charts/rig-operator/templates/crd.yaml", "w") as f:
f.write(result)
1 change: 1 addition & 0 deletions taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ tasks:
output:rbac:dir=deploy/kustomize/rbac \
output:webhook:dir=deploy/kustomize/webhook \
output:crd:dir=deploy/kustomize/crd/bases
- python3 ./scripts/crdcopy.py

generate-k8s:
desc: "🪄 Run runtime.Object implementaion generation"
Expand Down
Loading