diff --git a/PROJECT b/PROJECT index fa1ee155..47b8c332 100644 --- a/PROJECT +++ b/PROJECT @@ -15,8 +15,8 @@ resources: domain: spinoperator.dev group: core kind: SpinApp - path: github.com/spinkube/spin-operator/api/v1 - version: v1 + path: github.com/spinkube/spin-operator/api/v1alpha1 + version: v1alpha1 webhooks: defaulting: true validation: true @@ -28,8 +28,8 @@ resources: domain: spinoperator.dev group: core kind: SpinAppExecutor - path: github.com/spinkube/spin-operator/api/v1 - version: v1 + path: github.com/spinkube/spin-operator/api/v1alpha1 + version: v1alpha1 webhooks: defaulting: true validation: true diff --git a/api/v1/groupversion_info.go b/api/v1alpha1/groupversion_info.go similarity index 89% rename from api/v1/groupversion_info.go rename to api/v1alpha1/groupversion_info.go index f29a1042..649607cb 100644 --- a/api/v1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package v1 contains API Schema definitions for the spin v1 API group +// Package v1alpha1 contains API Schema definitions for the spin v1alpha1 API group // +kubebuilder:object:generate=true // +groupName=core.spinoperator.dev -package v1 +package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime/schema" @@ -26,7 +26,7 @@ import ( var ( // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "core.spinoperator.dev", Version: "v1"} + GroupVersion = schema.GroupVersion{Group: "core.spinoperator.dev", Version: "v1alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} diff --git a/api/v1/spinapp_types.go b/api/v1alpha1/spinapp_types.go similarity index 99% rename from api/v1/spinapp_types.go rename to api/v1alpha1/spinapp_types.go index e27adc0c..0b99fc96 100644 --- a/api/v1/spinapp_types.go +++ b/api/v1alpha1/spinapp_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1alpha1 import ( corev1 "k8s.io/api/core/v1" diff --git a/api/v1/spinappexecutor_types.go b/api/v1alpha1/spinappexecutor_types.go similarity index 99% rename from api/v1/spinappexecutor_types.go rename to api/v1alpha1/spinappexecutor_types.go index 90b9e7f9..48b9a47c 100644 --- a/api/v1/spinappexecutor_types.go +++ b/api/v1alpha1/spinappexecutor_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go similarity index 97% rename from api/v1/zz_generated.deepcopy.go rename to api/v1alpha1/zz_generated.deepcopy.go index 95f74e3c..c36d78c5 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -18,10 +18,10 @@ limitations under the License. // Code generated by controller-gen. DO NOT EDIT. -package v1 +package v1alpha1 import ( - corev1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -170,14 +170,14 @@ func (in *Resources) DeepCopyInto(out *Resources) { *out = *in if in.Limits != nil { in, out := &in.Limits, &out.Limits - *out = make(corev1.ResourceList, len(*in)) + *out = make(v1.ResourceList, len(*in)) for key, val := range *in { (*out)[key] = val.DeepCopy() } } if in.Requests != nil { in, out := &in.Requests, &out.Requests - *out = make(corev1.ResourceList, len(*in)) + *out = make(v1.ResourceList, len(*in)) for key, val := range *in { (*out)[key] = val.DeepCopy() } @@ -253,12 +253,12 @@ func (in *RuntimeConfigVarSource) DeepCopyInto(out *RuntimeConfigVarSource) { *out = *in if in.ConfigMapKeyRef != nil { in, out := &in.ConfigMapKeyRef, &out.ConfigMapKeyRef - *out = new(corev1.ConfigMapKeySelector) + *out = new(v1.ConfigMapKeySelector) (*in).DeepCopyInto(*out) } if in.SecretKeyRef != nil { in, out := &in.SecretKeyRef, &out.SecretKeyRef - *out = new(corev1.SecretKeySelector) + *out = new(v1.SecretKeySelector) (*in).DeepCopyInto(*out) } } @@ -431,21 +431,21 @@ func (in *SpinAppSpec) DeepCopyInto(out *SpinAppSpec) { *out = *in if in.ImagePullSecrets != nil { in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]corev1.LocalObjectReference, len(*in)) + *out = make([]v1.LocalObjectReference, len(*in)) copy(*out, *in) } in.Checks.DeepCopyInto(&out.Checks) in.RuntimeConfig.DeepCopyInto(&out.RuntimeConfig) if in.Volumes != nil { in, out := &in.Volumes, &out.Volumes - *out = make([]corev1.Volume, len(*in)) + *out = make([]v1.Volume, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.VolumeMounts != nil { in, out := &in.VolumeMounts, &out.VolumeMounts - *out = make([]corev1.VolumeMount, len(*in)) + *out = make([]v1.VolumeMount, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -518,7 +518,7 @@ func (in *SpinVar) DeepCopyInto(out *SpinVar) { *out = *in if in.ValueFrom != nil { in, out := &in.ValueFrom, &out.ValueFrom - *out = new(corev1.EnvVarSource) + *out = new(v1.EnvVarSource) (*in).DeepCopyInto(*out) } } diff --git a/charts/spin-operator/templates/mutating-webhook-configuration.yaml b/charts/spin-operator/templates/mutating-webhook-configuration.yaml index f6d18a26..5002666e 100644 --- a/charts/spin-operator/templates/mutating-webhook-configuration.yaml +++ b/charts/spin-operator/templates/mutating-webhook-configuration.yaml @@ -13,14 +13,14 @@ webhooks: service: name: '{{ include "spin-operator.fullname" . }}-webhook-service' namespace: '{{ .Release.Namespace }}' - path: /mutate-core-spinoperator-dev-v1-spinapp + path: /mutate-core-spinoperator-dev-v1alpha1-spinapp failurePolicy: Fail name: mspinapp.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE @@ -33,14 +33,14 @@ webhooks: service: name: '{{ include "spin-operator.fullname" . }}-webhook-service' namespace: '{{ .Release.Namespace }}' - path: /mutate-core-spinoperator-dev-v1-spinappexecutor + path: /mutate-core-spinoperator-dev-v1alpha1-spinappexecutor failurePolicy: Fail name: mspinappexecutor.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE diff --git a/charts/spin-operator/templates/validating-webhook-configuration.yaml b/charts/spin-operator/templates/validating-webhook-configuration.yaml index 6c1df0ea..90a857a1 100644 --- a/charts/spin-operator/templates/validating-webhook-configuration.yaml +++ b/charts/spin-operator/templates/validating-webhook-configuration.yaml @@ -13,14 +13,14 @@ webhooks: service: name: '{{ include "spin-operator.fullname" . }}-webhook-service' namespace: '{{ .Release.Namespace }}' - path: /validate-core-spinoperator-dev-v1-spinapp + path: /validate-core-spinoperator-dev-v1alpha1-spinapp failurePolicy: Fail name: vspinapp.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE @@ -33,14 +33,14 @@ webhooks: service: name: '{{ include "spin-operator.fullname" . }}-webhook-service' namespace: '{{ .Release.Namespace }}' - path: /validate-core-spinoperator-dev-v1-spinappexecutor + path: /validate-core-spinoperator-dev-v1alpha1-spinappexecutor failurePolicy: Fail name: vspinappexecutor.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE diff --git a/cmd/main.go b/cmd/main.go index 35cc9f60..51b7ef86 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,7 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/controller" "github.com/spinkube/spin-operator/internal/webhook" //+kubebuilder:scaffold:imports @@ -48,7 +48,7 @@ var ( func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(spinv1.AddToScheme(scheme)) + utilruntime.Must(spinv1alpha1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } diff --git a/config/crd/bases/core.spinoperator.dev_spinappexecutors.yaml b/config/crd/bases/core.spinoperator.dev_spinappexecutors.yaml index a9f536ef..3e9fb6da 100644 --- a/config/crd/bases/core.spinoperator.dev_spinappexecutors.yaml +++ b/config/crd/bases/core.spinoperator.dev_spinappexecutors.yaml @@ -14,7 +14,7 @@ spec: singular: spinappexecutor scope: Namespaced versions: - - name: v1 + - name: v1alpha1 schema: openAPIV3Schema: description: SpinAppExecutor is the Schema for the spinappexecutors API diff --git a/config/crd/bases/core.spinoperator.dev_spinapps.yaml b/config/crd/bases/core.spinoperator.dev_spinapps.yaml index 1afb1c75..cbea19f1 100644 --- a/config/crd/bases/core.spinoperator.dev_spinapps.yaml +++ b/config/crd/bases/core.spinoperator.dev_spinapps.yaml @@ -24,7 +24,7 @@ spec: - jsonPath: .spec.executor name: Executor type: string - name: v1 + name: v1alpha1 schema: openAPIV3Schema: description: SpinApp is the Schema for the spinapps API diff --git a/config/samples/annotations.yaml b/config/samples/annotations.yaml index 31a3f8c9..c8734308 100644 --- a/config/samples/annotations.yaml +++ b/config/samples/annotations.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: annotations-spinapp diff --git a/config/samples/cyclotron.yaml b/config/samples/cyclotron.yaml index 64aca211..ee26f0e2 100644 --- a/config/samples/cyclotron.yaml +++ b/config/samples/cyclotron.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: cyclotron-spinapp diff --git a/config/samples/hpa.yaml b/config/samples/hpa.yaml index 1f571b49..0cfbe5ae 100644 --- a/config/samples/hpa.yaml +++ b/config/samples/hpa.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: hpa-spinapp diff --git a/config/samples/keda-app.yaml b/config/samples/keda-app.yaml index e2a1c56a..9ff52225 100644 --- a/config/samples/keda-app.yaml +++ b/config/samples/keda-app.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: keda-spinapp diff --git a/config/samples/private-image.yaml b/config/samples/private-image.yaml index e810bbc2..8821dd89 100644 --- a/config/samples/private-image.yaml +++ b/config/samples/private-image.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: private-image-spinapp diff --git a/config/samples/probes.yaml b/config/samples/probes.yaml index 46f2409c..1cd3e631 100644 --- a/config/samples/probes.yaml +++ b/config/samples/probes.yaml @@ -1,4 +1,4 @@ -apiVersion: spinoperator.dev/v1 +apiVersion: spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: healthchecks-spinapp diff --git a/config/samples/redis.yaml b/config/samples/redis.yaml index 86d613d1..44465579 100644 --- a/config/samples/redis.yaml +++ b/config/samples/redis.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: redis-spinapp diff --git a/config/samples/resources.yaml b/config/samples/resources.yaml index 90824522..5405f578 100644 --- a/config/samples/resources.yaml +++ b/config/samples/resources.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: resource-requirements-spinapp diff --git a/config/samples/runtime-config.yaml b/config/samples/runtime-config.yaml index 7ddd557d..0b00e57b 100644 --- a/config/samples/runtime-config.yaml +++ b/config/samples/runtime-config.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: runtime-config diff --git a/config/samples/simple.yaml b/config/samples/simple.yaml index fcbdbadc..b018f6a5 100644 --- a/config/samples/simple.yaml +++ b/config/samples/simple.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: simple-spinapp diff --git a/config/samples/spin-shim-executor.yaml b/config/samples/spin-shim-executor.yaml index 531f4dcd..000c390a 100644 --- a/config/samples/spin-shim-executor.yaml +++ b/config/samples/spin-shim-executor.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinAppExecutor metadata: name: containerd-shim-spin diff --git a/config/samples/variable-explorer.yaml b/config/samples/variable-explorer.yaml index 5d679e4a..8de89b3e 100644 --- a/config/samples/variable-explorer.yaml +++ b/config/samples/variable-explorer.yaml @@ -13,7 +13,7 @@ data: password: c2VjcmV0X3NhdWNlCg== --- kind: SpinApp -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 metadata: name: variable-explorer spec: diff --git a/config/samples/variables.yaml b/config/samples/variables.yaml index dba5c21c..a560e96d 100644 --- a/config/samples/variables.yaml +++ b/config/samples/variables.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: variables-spinapp diff --git a/config/samples/volume-mount.yaml b/config/samples/volume-mount.yaml index c0e60fbd..32f77fbd 100644 --- a/config/samples/volume-mount.yaml +++ b/config/samples/volume-mount.yaml @@ -1,4 +1,4 @@ -apiVersion: core.spinoperator.dev/v1 +apiVersion: core.spinoperator.dev/v1alpha1 kind: SpinApp metadata: name: volume-mount-spinapp diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index db5dba1c..f9ff6ba9 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -10,14 +10,14 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-core-spinoperator-dev-v1-spinapp + path: /mutate-core-spinoperator-dev-v1alpha1-spinapp failurePolicy: Fail name: mspinapp.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE @@ -30,14 +30,14 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-core-spinoperator-dev-v1-spinappexecutor + path: /mutate-core-spinoperator-dev-v1alpha1-spinappexecutor failurePolicy: Fail name: mspinappexecutor.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE @@ -56,14 +56,14 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-core-spinoperator-dev-v1-spinapp + path: /validate-core-spinoperator-dev-v1alpha1-spinapp failurePolicy: Fail name: vspinapp.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE @@ -76,14 +76,14 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-core-spinoperator-dev-v1-spinappexecutor + path: /validate-core-spinoperator-dev-v1alpha1-spinappexecutor failurePolicy: Fail name: vspinappexecutor.kb.io rules: - apiGroups: - core.spinoperator.dev apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE diff --git a/internal/controller/deployment.go b/internal/controller/deployment.go index 27c946ed..3a95b373 100644 --- a/internal/controller/deployment.go +++ b/internal/controller/deployment.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/generics" "github.com/spinkube/spin-operator/pkg/spinapp" corev1 "k8s.io/api/core/v1" @@ -43,7 +43,7 @@ func constructRuntimeConfigSecretMount(_ctx context.Context, secretName string) // any required volume mounts. A generated runtime secret is mutually // exclusive with a user-provided secret - this is to require _either_ a // manual runtime-config or a generated one from the crd. -func ConstructVolumeMountsForApp(ctx context.Context, app *spinv1.SpinApp, generatedRuntimeSecret string) ([]corev1.Volume, []corev1.VolumeMount, error) { +func ConstructVolumeMountsForApp(ctx context.Context, app *spinv1alpha1.SpinApp, generatedRuntimeSecret string) ([]corev1.Volume, []corev1.VolumeMount, error) { volumes := []corev1.Volume{} volumeMounts := []corev1.VolumeMount{} @@ -72,7 +72,7 @@ func ConstructVolumeMountsForApp(ctx context.Context, app *spinv1.SpinApp, gener // ConstructEnvForApp constructs the env for a spin app that runs as a k8s pod. // Variables are not guaranteed to stay backed by ENV. -func ConstructEnvForApp(ctx context.Context, app *spinv1.SpinApp) []corev1.EnvVar { +func ConstructEnvForApp(ctx context.Context, app *spinv1alpha1.SpinApp) []corev1.EnvVar { if len(app.Spec.Variables) == 0 { return nil } @@ -93,7 +93,7 @@ func ConstructEnvForApp(ctx context.Context, app *spinv1.SpinApp) []corev1.EnvVa return envs } -func SpinHealthCheckToCoreProbe(probe *spinv1.HealthProbe) (*corev1.Probe, error) { +func SpinHealthCheckToCoreProbe(probe *spinv1alpha1.HealthProbe) (*corev1.Probe, error) { if probe == nil { return nil, nil } @@ -110,7 +110,7 @@ func SpinHealthCheckToCoreProbe(probe *spinv1.HealthProbe) (*corev1.Probe, error HTTPGet: &corev1.HTTPGetAction{ Path: probe.HTTPGet.Path, Port: intstr.FromInt(spinapp.DefaultHTTPPort), - HTTPHeaders: generics.MapList(probe.HTTPGet.HTTPHeaders, func(h spinv1.HTTPHealthProbeHeader) corev1.HTTPHeader { + HTTPHeaders: generics.MapList(probe.HTTPGet.HTTPHeaders, func(h spinv1alpha1.HTTPHealthProbeHeader) corev1.HTTPHeader { return corev1.HTTPHeader{ Name: h.Name, Value: h.Value, @@ -126,7 +126,7 @@ func SpinHealthCheckToCoreProbe(probe *spinv1.HealthProbe) (*corev1.Probe, error }, nil } -func ConstructPodHealthChecks(app *spinv1.SpinApp) (readiness *corev1.Probe, liveness *corev1.Probe, err error) { +func ConstructPodHealthChecks(app *spinv1alpha1.SpinApp) (readiness *corev1.Probe, liveness *corev1.Probe, err error) { if app.Spec.Checks.Readiness == nil && app.Spec.Checks.Liveness == nil { return nil, nil, nil } diff --git a/internal/controller/deployment_test.go b/internal/controller/deployment_test.go index 38563468..97c22aa3 100644 --- a/internal/controller/deployment_test.go +++ b/internal/controller/deployment_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/pkg/spinapp" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -15,13 +15,13 @@ import ( clientgoscheme "k8s.io/client-go/kubernetes/scheme" ) -func minimalSpinApp() *spinv1.SpinApp { - return &spinv1.SpinApp{ +func minimalSpinApp() *spinv1alpha1.SpinApp { + return &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "my-app", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Executor: "containerd-shim-spin", Image: "fakereg.dev/noapp:latest", Replicas: 1, @@ -133,7 +133,7 @@ func TestConstructEnvForApp(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { app := minimalSpinApp() - app.Spec.Variables = []spinv1.SpinVar{ + app.Spec.Variables = []spinv1alpha1.SpinVar{ { Name: test.varName, Value: test.value, @@ -155,7 +155,7 @@ func TestSpinHealthCheckToCoreProbe(t *testing.T) { tests := []struct { name string - probe *spinv1.HealthProbe + probe *spinv1alpha1.HealthProbe expectedProbe *corev1.Probe expectedErr string }{ @@ -166,16 +166,16 @@ func TestSpinHealthCheckToCoreProbe(t *testing.T) { }, { name: "probe_missing_httpGet_spec", - probe: &spinv1.HealthProbe{}, + probe: &spinv1alpha1.HealthProbe{}, expectedProbe: nil, expectedErr: "probe exists but with unknown configuration", }, { name: "probe_full", - probe: &spinv1.HealthProbe{ - HTTPGet: &spinv1.HTTPHealthProbe{ + probe: &spinv1alpha1.HealthProbe{ + HTTPGet: &spinv1alpha1.HTTPHealthProbe{ Path: "/var", - HTTPHeaders: []spinv1.HTTPHealthProbeHeader{ + HTTPHeaders: []spinv1alpha1.HTTPHealthProbeHeader{ { Name: "header", Value: "value", @@ -227,7 +227,7 @@ func TestSpinHealthCheckToCoreProbe(t *testing.T) { func TestDeploymentLabel(t *testing.T) { scheme := registerAndGetScheme() app := minimalSpinApp() - deployment, err := constructDeployment(context.Background(), app, &spinv1.ExecutorDeploymentConfig{}, "", scheme) + deployment, err := constructDeployment(context.Background(), app, &spinv1alpha1.ExecutorDeploymentConfig{}, "", scheme) require.Nil(t, err) require.NotNil(t, deployment.ObjectMeta.Labels) @@ -237,7 +237,7 @@ func TestDeploymentLabel(t *testing.T) { func registerAndGetScheme() *runtime.Scheme { scheme := runtime.NewScheme() utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(spinv1.AddToScheme(scheme)) + utilruntime.Must(spinv1alpha1.AddToScheme(scheme)) return scheme } diff --git a/internal/controller/service.go b/internal/controller/service.go index 9e898a64..f18e2468 100644 --- a/internal/controller/service.go +++ b/internal/controller/service.go @@ -1,7 +1,7 @@ package controller import ( - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/pkg/spinapp" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -9,7 +9,7 @@ import ( ) // constructService builds a corev1.Service based on the configuration of a SpinApp. -func constructService(app *spinv1.SpinApp) *corev1.Service { +func constructService(app *spinv1alpha1.SpinApp) *corev1.Service { annotations := app.Spec.ServiceAnnotations if annotations == nil { annotations = map[string]string{} @@ -52,7 +52,7 @@ func constructService(app *spinv1.SpinApp) *corev1.Service { // constructAppLabels returns the labels to add to deployment/service // objects for the given SpinApp -func constructAppLabels(app *spinv1.SpinApp) map[string]string { +func constructAppLabels(app *spinv1alpha1.SpinApp) map[string]string { return map[string]string{ spinapp.NameLabelKey: app.Name, } diff --git a/internal/controller/spinapp_controller.go b/internal/controller/spinapp_controller.go index 46431147..6dc43dfb 100644 --- a/internal/controller/spinapp_controller.go +++ b/internal/controller/spinapp_controller.go @@ -33,7 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/pelletier/go-toml/v2" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/logging" "github.com/spinkube/spin-operator/internal/runtimeconfig" "github.com/spinkube/spin-operator/pkg/spinapp" @@ -67,7 +67,7 @@ type SpinAppReconciler struct { // SetupWithManager sets up the controller with the Manager. func (r *SpinAppReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&spinv1.SpinApp{}). + For(&spinv1alpha1.SpinApp{}). // Owns allows watching dependency resources for any changes Owns(&appsv1.Deployment{}). Owns(&corev1.Service{}). @@ -84,7 +84,7 @@ func (r *SpinAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct log.Debug("Reconciling SpinApp") // Check if the SpinApp exists - var spinApp spinv1.SpinApp + var spinApp spinv1alpha1.SpinApp if err := r.Client.Get(ctx, req.NamespacedName, &spinApp); err != nil { // TODO: This error logging is noisy log.Error(err, "Unable to fetch SpinApp") @@ -94,7 +94,7 @@ func (r *SpinAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct return ctrl.Result{}, client.IgnoreNotFound(err) } - var executor spinv1.SpinAppExecutor + var executor spinv1alpha1.SpinAppExecutor if err := r.Client.Get(ctx, types.NamespacedName{ // Executors must currently be defined in the same namespace as the app. // When we decide if the operator will be global or namespaced we may want @@ -146,7 +146,7 @@ func (r *SpinAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } // updateStatus updates the status of a SpinApp. -func (r *SpinAppReconciler) updateStatus(ctx context.Context, app *spinv1.SpinApp, executor *spinv1.SpinAppExecutor) error { +func (r *SpinAppReconciler) updateStatus(ctx context.Context, app *spinv1alpha1.SpinApp, executor *spinv1alpha1.SpinAppExecutor) error { log := logging.FromContext(ctx) // Our only status management is currently based on the resulting deployment @@ -224,7 +224,7 @@ func (r *SpinAppReconciler) updateStatus(ctx context.Context, app *spinv1.SpinAp } // reconcileDeployment creates a deployment if one does not exist and reconciles it if it does. -func (r *SpinAppReconciler) reconcileDeployment(ctx context.Context, app *spinv1.SpinApp, config *spinv1.ExecutorDeploymentConfig) error { +func (r *SpinAppReconciler) reconcileDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config *spinv1alpha1.ExecutorDeploymentConfig) error { log := logging.FromContext(ctx).WithValues("deployment", app.Name) rcBuilder := runtimeconfig.NewBuilder(r.Client) @@ -297,7 +297,7 @@ func (r *SpinAppReconciler) reconcileDeployment(ctx context.Context, app *spinv1 } // reconcileService creates a service if one does not exist and updates it if it does. -func (r *SpinAppReconciler) reconcileService(ctx context.Context, app *spinv1.SpinApp) error { +func (r *SpinAppReconciler) reconcileService(ctx context.Context, app *spinv1alpha1.SpinApp) error { log := logging.FromContext(ctx).WithValues("service", app.Name) desiredService := constructService(app) @@ -324,7 +324,7 @@ func (r *SpinAppReconciler) reconcileService(ctx context.Context, app *spinv1.Sp } // deleteDeployment deletes the deployment for a SpinApp. -func (r *SpinAppReconciler) deleteDeployment(ctx context.Context, app *spinv1.SpinApp) error { +func (r *SpinAppReconciler) deleteDeployment(ctx context.Context, app *spinv1alpha1.SpinApp) error { deployment, err := r.findDeploymentForApp(ctx, app) if err != nil { return err @@ -339,7 +339,7 @@ func (r *SpinAppReconciler) deleteDeployment(ctx context.Context, app *spinv1.Sp } // constructDeployment builds an appsv1.Deployment based on the configuration of a SpinApp. -func constructDeployment(ctx context.Context, app *spinv1.SpinApp, config *spinv1.ExecutorDeploymentConfig, +func constructDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config *spinv1alpha1.ExecutorDeploymentConfig, generatedRuntimeConfigSecretName string, scheme *runtime.Scheme) (*appsv1.Deployment, error) { // TODO: Once we land admission webhooks write some validation to make // replicas and enableAutoscaling mutually exclusive. @@ -446,7 +446,7 @@ func constructDeployment(ctx context.Context, app *spinv1.SpinApp, config *spinv } // findDeploymentForApp finds the deployment for a SpinApp. -func (r *SpinAppReconciler) findDeploymentForApp(ctx context.Context, app *spinv1.SpinApp) (*appsv1.Deployment, error) { +func (r *SpinAppReconciler) findDeploymentForApp(ctx context.Context, app *spinv1alpha1.SpinApp) (*appsv1.Deployment, error) { var deployment appsv1.Deployment err := r.Client.Get(ctx, types.NamespacedName{Name: app.Name, Namespace: app.Namespace}, &deployment) if err != nil { diff --git a/internal/controller/spinapp_controller_test.go b/internal/controller/spinapp_controller_test.go index e02a6175..fbe674f8 100644 --- a/internal/controller/spinapp_controller_test.go +++ b/internal/controller/spinapp_controller_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -62,7 +62,7 @@ func SetupEnvTest(t *testing.T) *envTestState { scheme := runtime.NewScheme() require.NoError(t, clientscheme.AddToScheme(scheme)) - err = spinv1.AddToScheme(scheme) + err = spinv1alpha1.AddToScheme(scheme) require.NoError(t, err) k8sClient, err := client.New(cfg, client.Options{Scheme: scheme}) @@ -140,14 +140,14 @@ func TestReconcile_Integration_Deployment_Respects_Executor_Config(t *testing.T) }() // Create an executor that creates a deployment with a given runtimeClassName - executor := &spinv1.SpinAppExecutor{ + executor := &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "executor", Namespace: "default", }, - Spec: spinv1.SpinAppExecutorSpec{ + Spec: spinv1alpha1.SpinAppExecutorSpec{ CreateDeployment: true, - DeploymentConfig: &spinv1.ExecutorDeploymentConfig{ + DeploymentConfig: &spinv1alpha1.ExecutorDeploymentConfig{ RuntimeClassName: "a-runtime-class", }, }, @@ -155,12 +155,12 @@ func TestReconcile_Integration_Deployment_Respects_Executor_Config(t *testing.T) require.NoError(t, envTest.k8sClient.Create(ctx, executor)) - spinApp := &spinv1.SpinApp{ + spinApp := &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "app", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Executor: "executor", Image: "ghcr.io/radu-matei/perftest:v1", }, @@ -203,14 +203,14 @@ func TestReconcile_Integration_RuntimeConfig(t *testing.T) { }() // Create an executor that creates a deployment with a given runtimeClassName - executor := &spinv1.SpinAppExecutor{ + executor := &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "executor", Namespace: "default", }, - Spec: spinv1.SpinAppExecutorSpec{ + Spec: spinv1alpha1.SpinAppExecutorSpec{ CreateDeployment: true, - DeploymentConfig: &spinv1.ExecutorDeploymentConfig{ + DeploymentConfig: &spinv1alpha1.ExecutorDeploymentConfig{ RuntimeClassName: "a-runtime-class", }, }, @@ -218,20 +218,20 @@ func TestReconcile_Integration_RuntimeConfig(t *testing.T) { require.NoError(t, envTest.k8sClient.Create(ctx, executor)) - spinApp := &spinv1.SpinApp{ + spinApp := &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "app", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Executor: "executor", Image: "ghcr.io/radu-matei/perftest:v1", - RuntimeConfig: spinv1.RuntimeConfig{ - KeyValueStores: []spinv1.KeyValueStoreConfig{ + RuntimeConfig: spinv1alpha1.RuntimeConfig{ + KeyValueStores: []spinv1alpha1.KeyValueStoreConfig{ { Name: "default", Type: "redis", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "url", Value: "redis://localhost:9000", @@ -291,7 +291,7 @@ func TestConstructDeployment_MinimalApp(t *testing.T) { app := minimalSpinApp() - cfg := &spinv1.ExecutorDeploymentConfig{ + cfg := &spinv1alpha1.ExecutorDeploymentConfig{ RuntimeClassName: "bananarama", } deployment, err := constructDeployment(context.Background(), app, cfg, "", nil) diff --git a/internal/controller/spinappexecutor_controller.go b/internal/controller/spinappexecutor_controller.go index b7a67f27..59cf0b84 100644 --- a/internal/controller/spinappexecutor_controller.go +++ b/internal/controller/spinappexecutor_controller.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/logging" ) @@ -46,16 +46,16 @@ type SpinAppExecutorReconciler struct { // SetupWithManager sets up the controller with the Manager. func (r *SpinAppExecutorReconciler) SetupWithManager(mgr ctrl.Manager) error { - if err := mgr.GetFieldIndexer().IndexField(context.Background(), &spinv1.SpinApp{}, spinAppExecutorKey, func(rawObj client.Object) []string { + if err := mgr.GetFieldIndexer().IndexField(context.Background(), &spinv1alpha1.SpinApp{}, spinAppExecutorKey, func(rawObj client.Object) []string { // grab the spinapp object, extract the executor... - spinapp := rawObj.(*spinv1.SpinApp) + spinapp := rawObj.(*spinv1alpha1.SpinApp) return []string{spinapp.Spec.Executor} }); err != nil { return err } return ctrl.NewControllerManagedBy(mgr). - For(&spinv1.SpinAppExecutor{}). + For(&spinv1alpha1.SpinAppExecutor{}). Complete(r) } @@ -69,7 +69,7 @@ func (r *SpinAppExecutorReconciler) Reconcile(ctx context.Context, req ctrl.Requ log.Debug("Reconciling SpinAppExecutor") // Check if the SpinAppExecutor exists - var executor spinv1.SpinAppExecutor + var executor spinv1alpha1.SpinAppExecutor if err := r.Client.Get(ctx, req.NamespacedName, &executor); err != nil { log.Error(err, "Unable to fetch SpinAppExecutor") // we'll ignore not-found errors, since they can't be fixed by an immediate @@ -96,10 +96,10 @@ func (r *SpinAppExecutorReconciler) Reconcile(ctx context.Context, req ctrl.Requ // handleDeletion makes sure no SpinApps are dependent on the SpinAppExecutor // before allowing it to be deleted. -func (r *SpinAppExecutorReconciler) handleDeletion(ctx context.Context, executor *spinv1.SpinAppExecutor) error { +func (r *SpinAppExecutorReconciler) handleDeletion(ctx context.Context, executor *spinv1alpha1.SpinAppExecutor) error { log := logging.FromContext(ctx) - var spinApps spinv1.SpinAppList + var spinApps spinv1alpha1.SpinAppList if err := r.Client.List(ctx, &spinApps, client.MatchingFields{spinAppExecutorKey: executor.Name}); err != nil { log.Error(err, "Unable to list SpinApps") return err @@ -113,7 +113,7 @@ func (r *SpinAppExecutorReconciler) handleDeletion(ctx context.Context, executor } // removeFinalizer removes the finalizer from a SpinAppExecutor. -func (r *SpinAppExecutorReconciler) removeFinalizer(ctx context.Context, executor *spinv1.SpinAppExecutor) error { +func (r *SpinAppExecutorReconciler) removeFinalizer(ctx context.Context, executor *spinv1alpha1.SpinAppExecutor) error { if controllerutil.ContainsFinalizer(executor, SpinOperatorFinalizer) { controllerutil.RemoveFinalizer(executor, SpinOperatorFinalizer) if err := r.Client.Update(ctx, executor); err != nil { @@ -124,7 +124,7 @@ func (r *SpinAppExecutorReconciler) removeFinalizer(ctx context.Context, executo } // ensureFinalizer ensures the finalizer is present on a SpinAppExecutor. -func (r *SpinAppExecutorReconciler) ensureFinalizer(ctx context.Context, executor *spinv1.SpinAppExecutor) error { +func (r *SpinAppExecutorReconciler) ensureFinalizer(ctx context.Context, executor *spinv1alpha1.SpinAppExecutor) error { if !controllerutil.ContainsFinalizer(executor, SpinOperatorFinalizer) { controllerutil.AddFinalizer(executor, SpinOperatorFinalizer) if err := r.Client.Update(ctx, executor); err != nil { diff --git a/internal/controller/spinappexecutor_controller_test.go b/internal/controller/spinappexecutor_controller_test.go index 423bc282..5be39ce0 100644 --- a/internal/controller/spinappexecutor_controller_test.go +++ b/internal/controller/spinappexecutor_controller_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" @@ -88,7 +88,7 @@ func TestSpinAppExecutorReconcile_ContainerDShimSpinExecutorCreate(t *testing.T) }() executor := testContainerdShimSpinExecutor() - list := &spinv1.SpinAppExecutorList{} + list := &spinv1alpha1.SpinAppExecutorList{} require.NoError(t, envTest.k8sClient.List(ctx, list)) require.True(t, len(list.Items) == 0) require.NoError(t, envTest.k8sClient.Create(ctx, executor)) @@ -116,7 +116,7 @@ func TestSpinAppExecutorReconcile_ContainerDShimSpinExecutorDelete(t *testing.T) wg.Done() }() - list := &spinv1.SpinAppExecutorList{} + list := &spinv1alpha1.SpinAppExecutorList{} require.NoError(t, envTest.k8sClient.List(ctx, list)) require.True(t, len(list.Items) == 1) require.NoError(t, envTest.k8sClient.Delete(ctx, executor)) @@ -124,15 +124,15 @@ func TestSpinAppExecutorReconcile_ContainerDShimSpinExecutorDelete(t *testing.T) require.True(t, len(list.Items) == 0) } -func testContainerdShimSpinExecutor() *spinv1.SpinAppExecutor { - return &spinv1.SpinAppExecutor{ +func testContainerdShimSpinExecutor() *spinv1alpha1.SpinAppExecutor { + return &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "test-executor", Namespace: "default", }, - Spec: spinv1.SpinAppExecutorSpec{ + Spec: spinv1alpha1.SpinAppExecutorSpec{ CreateDeployment: true, - DeploymentConfig: &spinv1.ExecutorDeploymentConfig{ + DeploymentConfig: &spinv1alpha1.ExecutorDeploymentConfig{ RuntimeClassName: "test-runtime", }, }, diff --git a/internal/runtimeconfig/runtime_config.go b/internal/runtimeconfig/runtime_config.go index 8b427ed1..faed1d73 100644 --- a/internal/runtimeconfig/runtime_config.go +++ b/internal/runtimeconfig/runtime_config.go @@ -65,7 +65,7 @@ import ( "context" "slices" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/generics" "github.com/spinkube/spin-operator/internal/logging" "golang.org/x/sync/errgroup" @@ -79,7 +79,7 @@ type Builder interface { // Build takes a spin app and attempts to fetch any dependent secrets and build // a Spin-compatible representation of the configuration that can be rendered into // a new Secret. - Build(ctx context.Context, app *spinv1.SpinApp) (*Spin, error) + Build(ctx context.Context, app *spinv1alpha1.SpinApp) (*Spin, error) } func NewBuilder(client client.Client) *K8sBuilder { @@ -92,7 +92,7 @@ type K8sBuilder struct { client client.Client } -func (k *K8sBuilder) Build(ctx context.Context, app *spinv1.SpinApp) (rc *Spin, err error) { +func (k *K8sBuilder) Build(ctx context.Context, app *spinv1alpha1.SpinApp) (rc *Spin, err error) { logger := logging.FromContext(ctx).WithValues("component", "runtime_config_builder") defer func() { if err != nil { @@ -195,7 +195,7 @@ func (e *dependencies) fetch(ctx context.Context, client client.Client) error { return g.Wait() } -func extractRuntimeConfigDependencies(app *spinv1.SpinApp) *dependencies { +func extractRuntimeConfigDependencies(app *spinv1alpha1.SpinApp) *dependencies { result := &dependencies{ Secrets: make(map[types.NamespacedName]*corev1.Secret), ConfigMaps: make(map[types.NamespacedName]*corev1.ConfigMap), @@ -207,7 +207,7 @@ func extractRuntimeConfigDependencies(app *spinv1.SpinApp) *dependencies { return result } - var configOptions []spinv1.RuntimeConfigOption + var configOptions []spinv1alpha1.RuntimeConfigOption if runtimeConfig.LLMCompute != nil { configOptions = append(configOptions, runtimeConfig.LLMCompute.Options...) @@ -219,7 +219,7 @@ func extractRuntimeConfigDependencies(app *spinv1.SpinApp) *dependencies { configOptions = append(configOptions, sqlDB.Options...) } - secretMapper := func(configOption spinv1.RuntimeConfigOption) *corev1.Secret { + secretMapper := func(configOption spinv1alpha1.RuntimeConfigOption) *corev1.Secret { if configOption.ValueFrom == nil { return nil } @@ -240,7 +240,7 @@ func extractRuntimeConfigDependencies(app *spinv1.SpinApp) *dependencies { return nil } - configMapMapper := func(configOption spinv1.RuntimeConfigOption) *corev1.ConfigMap { + configMapMapper := func(configOption spinv1alpha1.RuntimeConfigOption) *corev1.ConfigMap { if configOption.ValueFrom == nil { return nil } diff --git a/internal/runtimeconfig/runtime_config_test.go b/internal/runtimeconfig/runtime_config_test.go index d974cf34..7a91bc77 100644 --- a/internal/runtimeconfig/runtime_config_test.go +++ b/internal/runtimeconfig/runtime_config_test.go @@ -3,7 +3,7 @@ package runtimeconfig import ( "testing" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -29,23 +29,23 @@ func configMapSelector(name string) *corev1.ConfigMapKeySelector { func Test_ExtractRuntimeConfigDependencies(t *testing.T) { t.Parallel() - basicSpec := spinv1.SpinAppSpec{} + basicSpec := spinv1alpha1.SpinAppSpec{} table := []struct { name string - inputAppSpec func() spinv1.SpinAppSpec + inputAppSpec func() spinv1alpha1.SpinAppSpec expectedSecrets []types.NamespacedName expectedConfigMaps []types.NamespacedName }{ { name: "only_static_values", - inputAppSpec: func() spinv1.SpinAppSpec { + inputAppSpec: func() spinv1alpha1.SpinAppSpec { spec := basicSpec - spec.RuntimeConfig.KeyValueStores = []spinv1.KeyValueStoreConfig{ + spec.RuntimeConfig.KeyValueStores = []spinv1alpha1.KeyValueStoreConfig{ { Name: "my-kv-store", Type: "magical", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "secret", Value: "i-put-secrets-in-plain-text", @@ -59,30 +59,30 @@ func Test_ExtractRuntimeConfigDependencies(t *testing.T) { }, { name: "unique_configmaps", - inputAppSpec: func() spinv1.SpinAppSpec { + inputAppSpec: func() spinv1alpha1.SpinAppSpec { spec := basicSpec - spec.RuntimeConfig.SqliteDatabases = []spinv1.SqliteDatabaseConfig{ + spec.RuntimeConfig.SqliteDatabases = []spinv1alpha1.SqliteDatabaseConfig{ { Name: "my-turso-db", Type: "libsql", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "url", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ ConfigMapKeyRef: configMapSelector("my-cm-b"), }, }, }, }, } - spec.RuntimeConfig.KeyValueStores = []spinv1.KeyValueStoreConfig{ + spec.RuntimeConfig.KeyValueStores = []spinv1alpha1.KeyValueStoreConfig{ { Name: "my-kv-store", Type: "magical", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "secret", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ ConfigMapKeyRef: configMapSelector("my-cm-a"), }, }, @@ -105,30 +105,30 @@ func Test_ExtractRuntimeConfigDependencies(t *testing.T) { }, { name: "duplicate_config_maps", - inputAppSpec: func() spinv1.SpinAppSpec { + inputAppSpec: func() spinv1alpha1.SpinAppSpec { spec := basicSpec - spec.RuntimeConfig.SqliteDatabases = []spinv1.SqliteDatabaseConfig{ + spec.RuntimeConfig.SqliteDatabases = []spinv1alpha1.SqliteDatabaseConfig{ { Name: "my-turso-db", Type: "libsql", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "url", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ ConfigMapKeyRef: configMapSelector("my-cm-a"), }, }, }, }, } - spec.RuntimeConfig.KeyValueStores = []spinv1.KeyValueStoreConfig{ + spec.RuntimeConfig.KeyValueStores = []spinv1alpha1.KeyValueStoreConfig{ { Name: "my-kv-store", Type: "magical", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "secret", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ ConfigMapKeyRef: configMapSelector("my-cm-a"), }, }, @@ -147,30 +147,30 @@ func Test_ExtractRuntimeConfigDependencies(t *testing.T) { }, { name: "unique_secrets", - inputAppSpec: func() spinv1.SpinAppSpec { + inputAppSpec: func() spinv1alpha1.SpinAppSpec { spec := basicSpec - spec.RuntimeConfig.SqliteDatabases = []spinv1.SqliteDatabaseConfig{ + spec.RuntimeConfig.SqliteDatabases = []spinv1alpha1.SqliteDatabaseConfig{ { Name: "my-turso-db", Type: "libsql", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "url", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ SecretKeyRef: secretKeySelector("my-secret-b"), }, }, }, }, } - spec.RuntimeConfig.KeyValueStores = []spinv1.KeyValueStoreConfig{ + spec.RuntimeConfig.KeyValueStores = []spinv1alpha1.KeyValueStoreConfig{ { Name: "my-kv-store", Type: "magical", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "secret", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ SecretKeyRef: secretKeySelector("my-secret-a"), }, }, @@ -193,30 +193,30 @@ func Test_ExtractRuntimeConfigDependencies(t *testing.T) { }, { name: "duplicate_secrets", - inputAppSpec: func() spinv1.SpinAppSpec { + inputAppSpec: func() spinv1alpha1.SpinAppSpec { spec := basicSpec - spec.RuntimeConfig.SqliteDatabases = []spinv1.SqliteDatabaseConfig{ + spec.RuntimeConfig.SqliteDatabases = []spinv1alpha1.SqliteDatabaseConfig{ { Name: "my-turso-db", Type: "libsql", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "url", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ SecretKeyRef: secretKeySelector("my-secret-a"), }, }, }, }, } - spec.RuntimeConfig.KeyValueStores = []spinv1.KeyValueStoreConfig{ + spec.RuntimeConfig.KeyValueStores = []spinv1alpha1.KeyValueStoreConfig{ { Name: "my-kv-store", Type: "magical", - Options: []spinv1.RuntimeConfigOption{ + Options: []spinv1alpha1.RuntimeConfigOption{ { Name: "secret", - ValueFrom: &spinv1.RuntimeConfigVarSource{ + ValueFrom: &spinv1alpha1.RuntimeConfigVarSource{ SecretKeyRef: secretKeySelector("my-secret-a"), }, }, @@ -237,7 +237,7 @@ func Test_ExtractRuntimeConfigDependencies(t *testing.T) { for _, test := range table { t.Run(test.name, func(t *testing.T) { - app := &spinv1.SpinApp{ + app := &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: test.name, Namespace: "test-ns", diff --git a/internal/runtimeconfig/types.go b/internal/runtimeconfig/types.go index f8003878..4a2c5870 100644 --- a/internal/runtimeconfig/types.go +++ b/internal/runtimeconfig/types.go @@ -3,7 +3,7 @@ package runtimeconfig import ( "fmt" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/pkg/secret" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" @@ -37,7 +37,7 @@ func (s *Spin) AddKeyValueStore( name, storeType, namespace string, secrets map[types.NamespacedName]*corev1.Secret, configMaps map[types.NamespacedName]*corev1.ConfigMap, - opts []spinv1.RuntimeConfigOption) error { + opts []spinv1alpha1.RuntimeConfigOption) error { if s.KeyValueStores == nil { s.KeyValueStores = make(map[string]KeyValueStoreOptions) } @@ -59,7 +59,7 @@ func (s *Spin) AddSQLiteDatabase( name, storeType, namespace string, secrets map[types.NamespacedName]*corev1.Secret, configMaps map[types.NamespacedName]*corev1.ConfigMap, - opts []spinv1.RuntimeConfigOption) error { + opts []spinv1alpha1.RuntimeConfigOption) error { if s.SQLiteDatabases == nil { s.SQLiteDatabases = make(map[string]SQLiteDatabaseOptions) } @@ -79,7 +79,7 @@ func (s *Spin) AddSQLiteDatabase( func (s *Spin) AddLLMCompute(computeType, namespace string, secrets map[types.NamespacedName]*corev1.Secret, configMaps map[types.NamespacedName]*corev1.ConfigMap, - opts []spinv1.RuntimeConfigOption) error { + opts []spinv1alpha1.RuntimeConfigOption) error { computeOpts, err := renderOptionsIntoMap(computeType, namespace, opts, secrets, configMaps) if err != nil { return err @@ -90,7 +90,7 @@ func (s *Spin) AddLLMCompute(computeType, namespace string, } func renderOptionsIntoMap(typeOpt, namespace string, - opts []spinv1.RuntimeConfigOption, + opts []spinv1alpha1.RuntimeConfigOption, secrets map[types.NamespacedName]*corev1.Secret, configMaps map[types.NamespacedName]*corev1.ConfigMap) (map[string]secret.String, error) { options := map[string]secret.String{ "type": secret.String(typeOpt), diff --git a/internal/webhook/admission.go b/internal/webhook/admission.go index e5ee1536..d5a77da1 100644 --- a/internal/webhook/admission.go +++ b/internal/webhook/admission.go @@ -1,13 +1,13 @@ package webhook import ( - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" ) func SetupSpinAppWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). - For(&spinv1.SpinApp{}). + For(&spinv1alpha1.SpinApp{}). WithDefaulter(&SpinAppDefaulter{Client: mgr.GetClient()}). WithValidator(&SpinAppValidator{Client: mgr.GetClient()}). Complete() @@ -15,7 +15,7 @@ func SetupSpinAppWebhookWithManager(mgr ctrl.Manager) error { func SetupSpinAppExecutorWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). - For(&spinv1.SpinAppExecutor{}). + For(&spinv1alpha1.SpinAppExecutor{}). WithDefaulter(&SpinAppExecutorDefaulter{Client: mgr.GetClient()}). WithValidator(&SpinAppExecutorValidator{Client: mgr.GetClient()}). Complete() diff --git a/internal/webhook/admission_test.go b/internal/webhook/admission_test.go index 16f26157..3889ee89 100644 --- a/internal/webhook/admission_test.go +++ b/internal/webhook/admission_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/constants" "github.com/stretchr/testify/require" admissionv1 "k8s.io/api/admission/v1" @@ -64,7 +64,7 @@ func setupEnvTest(t *testing.T) *envTestState { scheme := runtime.NewScheme() require.NoError(t, clientscheme.AddToScheme(scheme)) - err = spinv1.AddToScheme(scheme) + err = spinv1alpha1.AddToScheme(scheme) require.NoError(t, err) err = admissionv1.AddToScheme(scheme) @@ -142,12 +142,12 @@ func TestCreateSpinAppWithNoExecutor(t *testing.T) { envtest := setupEnvTest(t) startWebhookServer(t, envtest) - err := envtest.k8sClient.Create(context.Background(), &spinv1.SpinApp{ + err := envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "spinapp", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Image: "ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0", Replicas: 2, }, @@ -162,7 +162,7 @@ func TestCreateSpinAppWithSingleExecutor(t *testing.T) { envtest := setupEnvTest(t) startWebhookServer(t, envtest) - err := envtest.k8sClient.Create(context.Background(), &spinv1.SpinAppExecutor{ + err := envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "cyclotron", Namespace: "default", @@ -170,19 +170,19 @@ func TestCreateSpinAppWithSingleExecutor(t *testing.T) { }) require.NoError(t, err) - err = envtest.k8sClient.Create(context.Background(), &spinv1.SpinApp{ + err = envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "spinapp", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Image: "ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0", Replicas: 2, }, }) require.NoError(t, err) - spinapp := &spinv1.SpinApp{} + spinapp := &spinv1alpha1.SpinApp{} err = envtest.k8sClient.Get(context.Background(), client.ObjectKey{ Name: "spinapp", Namespace: "default", @@ -198,7 +198,7 @@ func TestCreateSpinAppWithMultipleExecutors(t *testing.T) { envtest := setupEnvTest(t) startWebhookServer(t, envtest) - err := envtest.k8sClient.Create(context.Background(), &spinv1.SpinAppExecutor{ + err := envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "containerd-shim-spin", Namespace: "default", @@ -206,7 +206,7 @@ func TestCreateSpinAppWithMultipleExecutors(t *testing.T) { }) require.NoError(t, err) - err = envtest.k8sClient.Create(context.Background(), &spinv1.SpinAppExecutor{ + err = envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "cyclotron", Namespace: "default", @@ -214,19 +214,19 @@ func TestCreateSpinAppWithMultipleExecutors(t *testing.T) { }) require.NoError(t, err) - err = envtest.k8sClient.Create(context.Background(), &spinv1.SpinApp{ + err = envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "spinapp", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Image: "ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0", Replicas: 2, }, }) require.NoError(t, err) - spinapp := &spinv1.SpinApp{} + spinapp := &spinv1alpha1.SpinApp{} err = envtest.k8sClient.Get(context.Background(), client.ObjectKey{ Name: "spinapp", Namespace: "default", @@ -243,7 +243,7 @@ func TestCreateInvalidSpinApp(t *testing.T) { envtest := setupEnvTest(t) startWebhookServer(t, envtest) - err := envtest.k8sClient.Create(context.Background(), &spinv1.SpinAppExecutor{ + err := envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "containerd-shim-spin", Namespace: "default", @@ -251,12 +251,12 @@ func TestCreateInvalidSpinApp(t *testing.T) { }) require.NoError(t, err) - err = envtest.k8sClient.Create(context.Background(), &spinv1.SpinApp{ + err = envtest.k8sClient.Create(context.Background(), &spinv1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: "spinapp", Namespace: "default", }, - Spec: spinv1.SpinAppSpec{ + Spec: spinv1alpha1.SpinAppSpec{ Image: "ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0", Replicas: -1, }, diff --git a/internal/webhook/spinapp_defaulting.go b/internal/webhook/spinapp_defaulting.go index 5c77f9c3..e651710b 100644 --- a/internal/webhook/spinapp_defaulting.go +++ b/internal/webhook/spinapp_defaulting.go @@ -4,14 +4,14 @@ import ( "context" "strings" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/logging" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) // nolint:lll -//+kubebuilder:webhook:path=/mutate-core-spinoperator-dev-v1-spinapp,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinapps,verbs=create;update,versions=v1,name=mspinapp.kb.io,admissionReviewVersions=v1 +//+kubebuilder:webhook:path=/mutate-core-spinoperator-dev-v1alpha1-spinapp,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinapps,verbs=create;update,versions=v1alpha1,name=mspinapp.kb.io,admissionReviewVersions=v1 // SpinAppDefaulter mutates SpinApps type SpinAppDefaulter struct { @@ -22,7 +22,7 @@ type SpinAppDefaulter struct { func (d *SpinAppDefaulter) Default(ctx context.Context, obj runtime.Object) error { log := logging.FromContext(ctx) - spinApp := obj.(*spinv1.SpinApp) + spinApp := obj.(*spinv1alpha1.SpinApp) log.Info("default", "name", spinApp.Name) if spinApp.Spec.Executor == "" { @@ -44,7 +44,7 @@ func (d *SpinAppDefaulter) Default(ctx context.Context, obj runtime.Object) erro func (d *SpinAppDefaulter) findDefaultExecutor(ctx context.Context) (string, error) { log := logging.FromContext(ctx) - var executors spinv1.SpinAppExecutorList + var executors spinv1alpha1.SpinAppExecutorList if err := d.Client.List(ctx, &executors); err != nil { log.Error(err, "failed to list SpinAppExecutors") return "", err diff --git a/internal/webhook/spinapp_defaulting_test.go b/internal/webhook/spinapp_defaulting_test.go index 57323d32..135905ce 100644 --- a/internal/webhook/spinapp_defaulting_test.go +++ b/internal/webhook/spinapp_defaulting_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/constants" "github.com/stretchr/testify/require" ) @@ -14,7 +14,7 @@ func TestDefaultNothingToSet(t *testing.T) { defaulter := &SpinAppDefaulter{} - spinApp := &spinv1.SpinApp{Spec: spinv1.SpinAppSpec{ + spinApp := &spinv1alpha1.SpinApp{Spec: spinv1alpha1.SpinAppSpec{ Executor: constants.CyclotronExecutor, Replicas: 1, }} diff --git a/internal/webhook/spinapp_validating.go b/internal/webhook/spinapp_validating.go index 3baac98e..53f8453f 100644 --- a/internal/webhook/spinapp_validating.go +++ b/internal/webhook/spinapp_validating.go @@ -3,7 +3,7 @@ package webhook import ( "context" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/logging" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -15,7 +15,7 @@ import ( ) // nolint:lll -//+kubebuilder:webhook:path=/validate-core-spinoperator-dev-v1-spinapp,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinapps,verbs=create;update,versions=v1,name=vspinapp.kb.io,admissionReviewVersions=v1 +//+kubebuilder:webhook:path=/validate-core-spinoperator-dev-v1alpha1-spinapp,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinapps,verbs=create;update,versions=v1alpha1,name=vspinapp.kb.io,admissionReviewVersions=v1 // SpinAppValidator validates SpinApps type SpinAppValidator struct { @@ -26,7 +26,7 @@ type SpinAppValidator struct { func (v *SpinAppValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { log := logging.FromContext(ctx) - spinApp := obj.(*spinv1.SpinApp) + spinApp := obj.(*spinv1alpha1.SpinApp) log.Info("validate create", "name", spinApp.Name) return nil, v.validateSpinApp(ctx, spinApp) @@ -36,7 +36,7 @@ func (v *SpinAppValidator) ValidateCreate(ctx context.Context, obj runtime.Objec func (v *SpinAppValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { log := logging.FromContext(ctx) - spinApp := newObj.(*spinv1.SpinApp) + spinApp := newObj.(*spinv1alpha1.SpinApp) log.Info("validate update", "name", spinApp.Name) return nil, v.validateSpinApp(ctx, spinApp) @@ -46,13 +46,13 @@ func (v *SpinAppValidator) ValidateUpdate(ctx context.Context, oldObj, newObj ru func (v *SpinAppValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { log := logging.FromContext(ctx) - spinApp := obj.(*spinv1.SpinApp) + spinApp := obj.(*spinv1alpha1.SpinApp) log.Info("validate delete", "name", spinApp.Name) return nil, nil } -func (v *SpinAppValidator) validateSpinApp(ctx context.Context, spinApp *spinv1.SpinApp) error { +func (v *SpinAppValidator) validateSpinApp(ctx context.Context, spinApp *spinv1alpha1.SpinApp) error { var allErrs field.ErrorList executor, err := validateExecutor(spinApp.Spec, v.fetchExecutor(ctx, spinApp.Namespace)) if err != nil { @@ -76,9 +76,9 @@ func (v *SpinAppValidator) validateSpinApp(ctx context.Context, spinApp *spinv1. // fetchExecutor returns a function that fetches a named executor in the provided namespace. // // We assume that the executor must exist in the same namespace as the SpinApp. -func (v *SpinAppValidator) fetchExecutor(ctx context.Context, spinAppNs string) func(name string) (*spinv1.SpinAppExecutor, error) { - return func(name string) (*spinv1.SpinAppExecutor, error) { - var executor spinv1.SpinAppExecutor +func (v *SpinAppValidator) fetchExecutor(ctx context.Context, spinAppNs string) func(name string) (*spinv1alpha1.SpinAppExecutor, error) { + return func(name string) (*spinv1alpha1.SpinAppExecutor, error) { + var executor spinv1alpha1.SpinAppExecutor if err := v.Client.Get(ctx, client.ObjectKey{Name: name, Namespace: spinAppNs}, &executor); err != nil { return nil, err } @@ -87,7 +87,7 @@ func (v *SpinAppValidator) fetchExecutor(ctx context.Context, spinAppNs string) } } -func validateExecutor(spec spinv1.SpinAppSpec, fetchExecutor func(name string) (*spinv1.SpinAppExecutor, error)) (*spinv1.SpinAppExecutor, *field.Error) { +func validateExecutor(spec spinv1alpha1.SpinAppSpec, fetchExecutor func(name string) (*spinv1alpha1.SpinAppExecutor, error)) (*spinv1alpha1.SpinAppExecutor, *field.Error) { if spec.Executor == "" { return nil, field.Invalid( field.NewPath("spec").Child("executor"), @@ -103,7 +103,7 @@ func validateExecutor(spec spinv1.SpinAppSpec, fetchExecutor func(name string) ( return executor, nil } -func validateReplicas(spec spinv1.SpinAppSpec) *field.Error { +func validateReplicas(spec spinv1alpha1.SpinAppSpec) *field.Error { if spec.EnableAutoscaling && spec.Replicas != 0 { return field.Invalid(field.NewPath("spec").Child("replicas"), spec.Replicas, "replicas cannot be set when autoscaling is enabled") } @@ -114,7 +114,7 @@ func validateReplicas(spec spinv1.SpinAppSpec) *field.Error { return nil } -func validateAnnotations(spec spinv1.SpinAppSpec, executor *spinv1.SpinAppExecutor) *field.Error { +func validateAnnotations(spec spinv1alpha1.SpinAppSpec, executor *spinv1alpha1.SpinAppExecutor) *field.Error { // We can't do any validation if the executor isn't available, but validation // will fail because of earlier errors. if executor == nil { diff --git a/internal/webhook/spinapp_validating_test.go b/internal/webhook/spinapp_validating_test.go index aac75243..aa258d8c 100644 --- a/internal/webhook/spinapp_validating_test.go +++ b/internal/webhook/spinapp_validating_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/constants" "github.com/stretchr/testify/require" ) @@ -12,43 +12,43 @@ import ( func TestValidateExecutor(t *testing.T) { t.Parallel() - _, fldErr := validateExecutor(spinv1.SpinAppSpec{}, func(string) (*spinv1.SpinAppExecutor, error) { return nil, nil }) + _, fldErr := validateExecutor(spinv1alpha1.SpinAppSpec{}, func(string) (*spinv1alpha1.SpinAppExecutor, error) { return nil, nil }) require.EqualError(t, fldErr, "spec.executor: Invalid value: \"\": executor must be set, likely no default executor was set because you have no executors installed") _, fldErr = validateExecutor( - spinv1.SpinAppSpec{Executor: constants.CyclotronExecutor}, - func(string) (*spinv1.SpinAppExecutor, error) { return nil, errors.New("executor not found?") }) + spinv1alpha1.SpinAppSpec{Executor: constants.CyclotronExecutor}, + func(string) (*spinv1alpha1.SpinAppExecutor, error) { return nil, errors.New("executor not found?") }) require.EqualError(t, fldErr, "spec.executor: Invalid value: \"cyclotron\": executor does not exist on cluster") - _, fldErr = validateExecutor(spinv1.SpinAppSpec{Executor: constants.ContainerDShimSpinExecutor}, func(string) (*spinv1.SpinAppExecutor, error) { return nil, nil }) + _, fldErr = validateExecutor(spinv1alpha1.SpinAppSpec{Executor: constants.ContainerDShimSpinExecutor}, func(string) (*spinv1alpha1.SpinAppExecutor, error) { return nil, nil }) require.Nil(t, fldErr) } func TestValidateReplicas(t *testing.T) { t.Parallel() - fldErr := validateReplicas(spinv1.SpinAppSpec{}) + fldErr := validateReplicas(spinv1alpha1.SpinAppSpec{}) require.EqualError(t, fldErr, "spec.replicas: Invalid value: 0: replicas must be > 0") - fldErr = validateReplicas(spinv1.SpinAppSpec{Replicas: 1}) + fldErr = validateReplicas(spinv1alpha1.SpinAppSpec{Replicas: 1}) require.Nil(t, fldErr) } func TestValidateAnnotations(t *testing.T) { t.Parallel() - deploymentlessExecutor := &spinv1.SpinAppExecutor{ - Spec: spinv1.SpinAppExecutorSpec{ + deploymentlessExecutor := &spinv1alpha1.SpinAppExecutor{ + Spec: spinv1alpha1.SpinAppExecutorSpec{ CreateDeployment: false, }, } - deploymentfullExecutor := &spinv1.SpinAppExecutor{ - Spec: spinv1.SpinAppExecutorSpec{ + deploymentfullExecutor := &spinv1alpha1.SpinAppExecutor{ + Spec: spinv1alpha1.SpinAppExecutorSpec{ CreateDeployment: true, }, } - fldErr := validateAnnotations(spinv1.SpinAppSpec{ + fldErr := validateAnnotations(spinv1alpha1.SpinAppSpec{ Executor: "an-executor", DeploymentAnnotations: map[string]string{"key": "asdf"}, }, deploymentlessExecutor) @@ -56,7 +56,7 @@ func TestValidateAnnotations(t *testing.T) { `spec.deploymentAnnotations: Invalid value: map[string]string{"key":"asdf"}: `+ `deploymentAnnotations can't be set when the executor does not use operator deployments`) - fldErr = validateAnnotations(spinv1.SpinAppSpec{ + fldErr = validateAnnotations(spinv1alpha1.SpinAppSpec{ Executor: "an-executor", PodAnnotations: map[string]string{"key": "asdf"}, }, deploymentlessExecutor) @@ -64,13 +64,13 @@ func TestValidateAnnotations(t *testing.T) { `spec.podAnnotations: Invalid value: map[string]string{"key":"asdf"}: `+ `podAnnotations can't be set when the executor does not use operator deployments`) - fldErr = validateAnnotations(spinv1.SpinAppSpec{ + fldErr = validateAnnotations(spinv1alpha1.SpinAppSpec{ Executor: "an-executor", DeploymentAnnotations: map[string]string{"key": "asdf"}, }, deploymentfullExecutor) require.Nil(t, fldErr) - fldErr = validateAnnotations(spinv1.SpinAppSpec{ + fldErr = validateAnnotations(spinv1alpha1.SpinAppSpec{ Executor: "an-executor", }, deploymentlessExecutor) require.Nil(t, fldErr) diff --git a/internal/webhook/spinappexecutor_defaulting.go b/internal/webhook/spinappexecutor_defaulting.go index e147f548..b926e68d 100644 --- a/internal/webhook/spinappexecutor_defaulting.go +++ b/internal/webhook/spinappexecutor_defaulting.go @@ -3,14 +3,14 @@ package webhook import ( "context" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/logging" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) // nolint:lll -//+kubebuilder:webhook:path=/mutate-core-spinoperator-dev-v1-spinappexecutor,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinappexecutors,verbs=create;update,versions=v1,name=mspinappexecutor.kb.io,admissionReviewVersions=v1 +//+kubebuilder:webhook:path=/mutate-core-spinoperator-dev-v1alpha1-spinappexecutor,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinappexecutors,verbs=create;update,versions=v1alpha1,name=mspinappexecutor.kb.io,admissionReviewVersions=v1 // SpinAppExecutorDefaulter mutates SpinApps type SpinAppExecutorDefaulter struct { @@ -21,7 +21,7 @@ type SpinAppExecutorDefaulter struct { func (d *SpinAppExecutorDefaulter) Default(ctx context.Context, obj runtime.Object) error { log := logging.FromContext(ctx) - executor := obj.(*spinv1.SpinAppExecutor) + executor := obj.(*spinv1alpha1.SpinAppExecutor) log.Info("default", "name", executor.Name) return nil diff --git a/internal/webhook/spinappexecutor_validating.go b/internal/webhook/spinappexecutor_validating.go index 65562daf..2d52347a 100644 --- a/internal/webhook/spinappexecutor_validating.go +++ b/internal/webhook/spinappexecutor_validating.go @@ -3,7 +3,7 @@ package webhook import ( "context" - spinv1 "github.com/spinkube/spin-operator/api/v1" + spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" "github.com/spinkube/spin-operator/internal/logging" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -12,7 +12,7 @@ import ( ) // nolint:lll -//+kubebuilder:webhook:path=/validate-core-spinoperator-dev-v1-spinappexecutor,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinappexecutors,verbs=create;update,versions=v1,name=vspinappexecutor.kb.io,admissionReviewVersions=v1 +//+kubebuilder:webhook:path=/validate-core-spinoperator-dev-v1alpha1-spinappexecutor,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.spinoperator.dev,resources=spinappexecutors,verbs=create;update,versions=v1alpha1,name=vspinappexecutor.kb.io,admissionReviewVersions=v1 // SpinAppExecutorValidator validates SpinApps type SpinAppExecutorValidator struct { @@ -23,7 +23,7 @@ type SpinAppExecutorValidator struct { func (v *SpinAppExecutorValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { log := logging.FromContext(ctx) - executor := obj.(*spinv1.SpinAppExecutor) + executor := obj.(*spinv1alpha1.SpinAppExecutor) log.Info("validate create", "name", executor.Name) return nil, v.validateSpinAppExecutor(executor) @@ -33,7 +33,7 @@ func (v *SpinAppExecutorValidator) ValidateCreate(ctx context.Context, obj runti func (v *SpinAppExecutorValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { log := logging.FromContext(ctx) - executor := newObj.(*spinv1.SpinAppExecutor) + executor := newObj.(*spinv1alpha1.SpinAppExecutor) log.Info("validate update", "name", executor.Name) return nil, v.validateSpinAppExecutor(executor) @@ -43,12 +43,12 @@ func (v *SpinAppExecutorValidator) ValidateUpdate(ctx context.Context, oldObj, n func (v *SpinAppExecutorValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { log := logging.FromContext(ctx) - executor := obj.(*spinv1.SpinAppExecutor) + executor := obj.(*spinv1alpha1.SpinAppExecutor) log.Info("validate delete", "name", executor.Name) return nil, nil } -func (v *SpinAppExecutorValidator) validateSpinAppExecutor(executor *spinv1.SpinAppExecutor) error { +func (v *SpinAppExecutorValidator) validateSpinAppExecutor(executor *spinv1alpha1.SpinAppExecutor) error { return nil }