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

Commit b56dc4d

Browse files
authored
Merge pull request #7 from spacelift-io/CU-8693y86jm-scaffolding-for-stack
Scaffolding for Stack
2 parents 3fb2d86 + 56e7473 commit b56dc4d

File tree

12 files changed

+379
-0
lines changed

12 files changed

+379
-0
lines changed

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ resources:
1616
kind: Run
1717
path: github.com/spacelift-io/spacelift-operator/api/v1beta1
1818
version: v1beta1
19+
- api:
20+
crdVersion: v1
21+
namespaced: true
22+
controller: true
23+
domain: app.spacelift.io
24+
kind: Stack
25+
path: github.com/spacelift-io/spacelift-operator/api/v1beta1
26+
version: v1beta1
1927
version: "3"

api/v1beta1/stack_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+
// StackSpec defines the desired state of Stack
27+
type StackSpec 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 Stack. Edit stack_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// StackStatus defines the observed state of Stack
36+
type StackStatus 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+
// Stack is the Schema for the stacks API
45+
type Stack struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec StackSpec `json:"spec,omitempty"`
50+
Status StackStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// StackList contains a list of Stack
56+
type StackList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []Stack `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&Stack{}, &StackList{})
64+
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 89 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ func main() {
113113
setupLog.Error(err, "unable to create controller", "controller", "Run")
114114
os.Exit(1)
115115
}
116+
if err = (&controller.StackReconciler{
117+
Client: mgr.GetClient(),
118+
Scheme: mgr.GetScheme(),
119+
}).SetupWithManager(mgr); err != nil {
120+
setupLog.Error(err, "unable to create controller", "controller", "Stack")
121+
os.Exit(1)
122+
}
116123
//+kubebuilder:scaffold:builder
117124

118125
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: stacks.app.spacelift.io
8+
spec:
9+
group: app.spacelift.io
10+
names:
11+
kind: Stack
12+
listKind: StackList
13+
plural: stacks
14+
singular: stack
15+
scope: Namespaced
16+
versions:
17+
- name: v1beta1
18+
schema:
19+
openAPIV3Schema:
20+
description: Stack is the Schema for the stacks 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: StackSpec defines the desired state of Stack
36+
properties:
37+
foo:
38+
description: Foo is an example field of Stack. Edit stack_types.go
39+
to remove/update
40+
type: string
41+
type: object
42+
status:
43+
description: StackStatus defines the observed state of Stack
44+
type: object
45+
type: object
46+
served: true
47+
storage: true
48+
subresources:
49+
status: {}

config/crd/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
# It should be run by config/default
44
resources:
55
- bases/app.spacelift.io_runs.yaml
6+
- bases/app.spacelift.io_stacks.yaml
67
#+kubebuilder:scaffold:crdkustomizeresource
78

89
patches:
910
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1011
# patches here are for enabling the conversion webhook for each CRD
1112
#- path: patches/webhook_in_runs.yaml
13+
#- path: patches/webhook_in_stacks.yaml
1214
#+kubebuilder:scaffold:crdkustomizewebhookpatch
1315

1416
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
1517
# patches here are for enabling the CA injection for each CRD
1618
#- path: patches/cainjection_in_runs.yaml
19+
#- path: patches/cainjection_in_stacks.yaml
1720
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
1821

1922
# the following config is for teaching kustomize how to do kustomization for CRDs.

config/rbac/role.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,29 @@ rules:
3030
- get
3131
- patch
3232
- update
33+
- apiGroups:
34+
- app.spacelift.io
35+
resources:
36+
- stacks
37+
verbs:
38+
- create
39+
- delete
40+
- get
41+
- list
42+
- patch
43+
- update
44+
- watch
45+
- apiGroups:
46+
- app.spacelift.io
47+
resources:
48+
- stacks/finalizers
49+
verbs:
50+
- update
51+
- apiGroups:
52+
- app.spacelift.io
53+
resources:
54+
- stacks/status
55+
verbs:
56+
- get
57+
- patch
58+
- update

config/rbac/stack_editor_role.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# permissions for end users to edit stacks.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: clusterrole
7+
app.kubernetes.io/instance: stack-editor-role
8+
app.kubernetes.io/component: rbac
9+
app.kubernetes.io/created-by: spacelift-operator
10+
app.kubernetes.io/part-of: spacelift-operator
11+
app.kubernetes.io/managed-by: kustomize
12+
name: stack-editor-role
13+
rules:
14+
- apiGroups:
15+
- app.spacelift.io
16+
resources:
17+
- stacks
18+
verbs:
19+
- create
20+
- delete
21+
- get
22+
- list
23+
- patch
24+
- update
25+
- watch
26+
- apiGroups:
27+
- app.spacelift.io
28+
resources:
29+
- stacks/status
30+
verbs:
31+
- get

config/rbac/stack_viewer_role.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# permissions for end users to view stacks.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: clusterrole
7+
app.kubernetes.io/instance: stack-viewer-role
8+
app.kubernetes.io/component: rbac
9+
app.kubernetes.io/created-by: spacelift-operator
10+
app.kubernetes.io/part-of: spacelift-operator
11+
app.kubernetes.io/managed-by: kustomize
12+
name: stack-viewer-role
13+
rules:
14+
- apiGroups:
15+
- app.spacelift.io
16+
resources:
17+
- stacks
18+
verbs:
19+
- get
20+
- list
21+
- watch
22+
- apiGroups:
23+
- app.spacelift.io
24+
resources:
25+
- stacks/status
26+
verbs:
27+
- get

config/samples/_v1beta1_stack.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: app.spacelift.io/v1beta1
2+
kind: Stack
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: stack
6+
app.kubernetes.io/instance: stack-sample
7+
app.kubernetes.io/part-of: spacelift-operator
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: spacelift-operator
10+
name: stack-sample
11+
spec:
12+
# TODO(user): Add fields here

0 commit comments

Comments
 (0)