Skip to content

Commit 0043b74

Browse files
committed
basics of the api and the deployment with a tiltfile
1 parent 5116619 commit 0043b74

20 files changed

+369
-376
lines changed

Tiltfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- mode: Starlark -*-
2+
3+
kubectl_cmd = "kubectl"
4+
5+
# verify kubectl command exists
6+
if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "":
7+
fail("Required command '" + kubectl_cmd + "' not found in PATH")
8+
9+
# Use kustomize to build the install yaml files
10+
install = kustomize('config/default')
11+
12+
# Update the root security group. Tilt requires root access to update the
13+
# running process.
14+
objects = decode_yaml_stream(install)
15+
for o in objects:
16+
if o.get('kind') == 'Deployment' and o.get('metadata').get('name') == 'crd-bootstrap-controller-manager':
17+
o['spec']['template']['spec']['securityContext']['runAsNonRoot'] = False
18+
break
19+
20+
updated_install = encode_yaml_stream(objects)
21+
22+
# Apply the updated yaml to the cluster.
23+
# Allow duplicates so the e2e test can include this tilt file with other tilt files
24+
# setting up the same namespace.
25+
k8s_yaml(updated_install, allow_duplicates = True)
26+
27+
load('ext://restart_process', 'docker_build_with_restart')
28+
29+
# enable hot reloading by doing the following:
30+
# - locally build the whole project
31+
# - create a docker imagine using tilt's hot-swap wrapper
32+
# - push that container to the local tilt registry
33+
# Once done, rebuilding now should be a lot faster since only the relevant
34+
# binary is rebuilt and the hot swat wrapper takes care of the rest.
35+
local_resource(
36+
'crd-bootstrap-controller-binary',
37+
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager ./',
38+
deps = [
39+
"main.go",
40+
"go.mod",
41+
"go.sum",
42+
"api",
43+
"controllers",
44+
"pkg",
45+
],
46+
)
47+
48+
# Build the docker image for our controller. We use a specific Dockerfile
49+
# since tilt can't run on a scratch container.
50+
# `only` here is important, otherwise, the container will get updated
51+
# on _any_ file change. We only want to monitor the binary.
52+
# If debugging is enabled, we switch to a different docker file using
53+
# the delve port.
54+
entrypoint = ['/manager']
55+
dockerfile = 'tilt.dockerfile'
56+
docker_build_with_restart(
57+
'ghcr.io/Skarlso/crd-bootstrap-controller',
58+
'.',
59+
dockerfile = dockerfile,
60+
entrypoint = entrypoint,
61+
only=[
62+
'./bin',
63+
],
64+
live_update = [
65+
sync('./bin/manager', '/manager'),
66+
],
67+
)

api/v1alpha1/bootstrap_types.go

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,78 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

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.
23+
// GitHub defines a GitHub type source where the CRD is coming from `release` section of a GitHub repository.
24+
type GitHub struct {
25+
}
26+
27+
// ConfigMap defines a reference to a configmap which hold the CRD information. Version is taken from a version field.
28+
type ConfigMap struct {
29+
// +required
30+
Name string `json:"name"`
31+
// +required
32+
Version string `json:"version"`
33+
}
34+
35+
// URL holds a URL from which to fetch the CRD. Version is defined through the digest of the content.
36+
type URL struct {
37+
URL string `json:"url"`
38+
}
39+
40+
// Source defines options from where to fetch CRD content.
41+
type Source struct {
42+
// +optional
43+
GitHub *GitHub `json:"gitHub,omitempty"`
44+
// +optional
45+
ConfigMap *ConfigMap `json:"configMap,omitempty"`
46+
// +optional
47+
URL *URL `json:"url,omitempty"`
48+
}
2549

2650
// BootstrapSpec defines the desired state of Bootstrap
2751
type BootstrapSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
52+
// Interval defines the regular interval at which a poll for new version should happen.
53+
// +optional
54+
Interval metav1.Time `json:"interval,omitempty"`
55+
56+
// SourceRef defines a reference to a source which will provide a CRD based on some contract.
57+
// +required
58+
Source *Source `json:"source"`
3059

31-
// Foo is an example field of Bootstrap. Edit bootstrap_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
60+
// TemplateRef defines a reference to a configmap which holds a template that we will use to verify that
61+
// the CRD doesn't break anything if applied.
62+
// +required
63+
TemplateRef string `json:"templateRef"`
3364
}
3465

3566
// BootstrapStatus defines the observed state of Bootstrap
3667
type BootstrapStatus struct {
37-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38-
// Important: Run "make" to regenerate code after modifying this file
68+
// ObservedGeneration is the last reconciled generation.
69+
// +optional
70+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
71+
72+
// +optional
73+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
74+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""
75+
Conditions []metav1.Condition `json:"conditions,omitempty"`
76+
77+
// +optional
78+
LastAttemptedVersion string `json:"lastAttemptedVersion,omitempty"`
79+
80+
// +optional
81+
LastAppliedVersion string `json:"lastAppliedVersion,omitempty"`
82+
83+
// +optional
84+
LastAppliedDigest string `json:"lastAppliedDigest,omitempty"`
85+
}
86+
87+
// GetConditions returns the conditions of the ComponentVersion.
88+
func (in *Bootstrap) GetConditions() []metav1.Condition {
89+
return in.Status.Conditions
90+
}
91+
92+
// SetConditions sets the conditions of the ComponentVersion.
93+
func (in *Bootstrap) SetConditions(conditions []metav1.Condition) {
94+
in.Status.Conditions = conditions
3995
}
4096

4197
//+kubebuilder:object:root=true

api/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)