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

Commit d41a0d6

Browse files
committed
feat: add Run CRD
1 parent a620e3f commit d41a0d6

19 files changed

+621
-0
lines changed

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,13 @@ layout:
77
- go.kubebuilder.io/v4
88
projectName: spacelift-operator
99
repo: github.com/spacelift-io/spacelift-operator
10+
resources:
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
controller: true
15+
domain: app.spacelift.io
16+
kind: Run
17+
path: github.com/spacelift-io/spacelift-operator/api/v1beta1
18+
version: v1beta1
1019
version: "3"

api/v1beta1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1beta1 contains API Schema definitions for the v1beta1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=app.spacelift.io
20+
package v1beta1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "app.spacelift.io", Version: "v1beta1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1beta1/run_types.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// RunSpec defines the desired state of Run
27+
type RunSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of Run. Edit run_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// RunStatus defines the observed state of Run
36+
type RunStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// Run is the Schema for the runs API
45+
type Run struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec RunSpec `json:"spec,omitempty"`
50+
Status RunStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// RunList contains a list of Run
56+
type RunList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []Run `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&Run{}, &RunList{})
64+
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/healthz"
3232
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3333
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
34+
35+
appspaceliftiov1beta1 "github.com/spacelift-io/spacelift-operator/api/v1beta1"
36+
"github.com/spacelift-io/spacelift-operator/internal/controller"
3437
//+kubebuilder:scaffold:imports
3538
)
3639

@@ -42,6 +45,7 @@ var (
4245
func init() {
4346
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
4447

48+
utilruntime.Must(appspaceliftiov1beta1.AddToScheme(scheme))
4549
//+kubebuilder:scaffold:scheme
4650
}
4751

@@ -85,6 +89,13 @@ func main() {
8589
os.Exit(1)
8690
}
8791

92+
if err = (&controller.RunReconciler{
93+
Client: mgr.GetClient(),
94+
Scheme: mgr.GetScheme(),
95+
}).SetupWithManager(mgr); err != nil {
96+
setupLog.Error(err, "unable to create controller", "controller", "Run")
97+
os.Exit(1)
98+
}
8899
//+kubebuilder:scaffold:builder
89100

90101
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.13.0
7+
name: runs.app.spacelift.io
8+
spec:
9+
group: app.spacelift.io
10+
names:
11+
kind: Run
12+
listKind: RunList
13+
plural: runs
14+
singular: run
15+
scope: Namespaced
16+
versions:
17+
- name: v1beta1
18+
schema:
19+
openAPIV3Schema:
20+
description: Run is the Schema for the runs API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
description: RunSpec defines the desired state of Run
36+
properties:
37+
foo:
38+
description: Foo is an example field of Run. Edit run_types.go to
39+
remove/update
40+
type: string
41+
type: object
42+
status:
43+
description: RunStatus defines the observed state of Run
44+
type: object
45+
type: object
46+
served: true
47+
storage: true
48+
subresources:
49+
status: {}

config/crd/kustomization.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This kustomization.yaml is not intended to be run by itself,
2+
# since it depends on service name and namespace that are out of this kustomize package.
3+
# It should be run by config/default
4+
resources:
5+
- bases/app.spacelift.io_runs.yaml
6+
#+kubebuilder:scaffold:crdkustomizeresource
7+
8+
patches:
9+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
10+
# patches here are for enabling the conversion webhook for each CRD
11+
#- path: patches/webhook_in_runs.yaml
12+
#+kubebuilder:scaffold:crdkustomizewebhookpatch
13+
14+
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
15+
# patches here are for enabling the CA injection for each CRD
16+
#- path: patches/cainjection_in_runs.yaml
17+
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
18+
19+
# the following config is for teaching kustomize how to do kustomization for CRDs.
20+
configurations:
21+
- kustomizeconfig.yaml

config/crd/kustomizeconfig.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
2+
nameReference:
3+
- kind: Service
4+
version: v1
5+
fieldSpecs:
6+
- kind: CustomResourceDefinition
7+
version: v1
8+
group: apiextensions.k8s.io
9+
path: spec/conversion/webhook/clientConfig/service/name
10+
11+
namespace:
12+
- kind: CustomResourceDefinition
13+
version: v1
14+
group: apiextensions.k8s.io
15+
path: spec/conversion/webhook/clientConfig/service/namespace
16+
create: false
17+
18+
varReference:
19+
- path: metadata/annotations
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME
7+
name: runs.app.spacelift.io
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following patch enables a conversion webhook for the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: runs.app.spacelift.io
6+
spec:
7+
conversion:
8+
strategy: Webhook
9+
webhook:
10+
clientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert
15+
conversionReviewVersions:
16+
- v1

0 commit comments

Comments
 (0)