Skip to content

Commit

Permalink
basics of the api and the deployment with a tiltfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Jun 19, 2023
1 parent 5116619 commit 0043b74
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 376 deletions.
67 changes: 67 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- mode: Starlark -*-

kubectl_cmd = "kubectl"

# verify kubectl command exists
if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "":
fail("Required command '" + kubectl_cmd + "' not found in PATH")

# Use kustomize to build the install yaml files
install = kustomize('config/default')

# Update the root security group. Tilt requires root access to update the
# running process.
objects = decode_yaml_stream(install)
for o in objects:
if o.get('kind') == 'Deployment' and o.get('metadata').get('name') == 'crd-bootstrap-controller-manager':
o['spec']['template']['spec']['securityContext']['runAsNonRoot'] = False
break

updated_install = encode_yaml_stream(objects)

# Apply the updated yaml to the cluster.
# Allow duplicates so the e2e test can include this tilt file with other tilt files
# setting up the same namespace.
k8s_yaml(updated_install, allow_duplicates = True)

load('ext://restart_process', 'docker_build_with_restart')

# enable hot reloading by doing the following:
# - locally build the whole project
# - create a docker imagine using tilt's hot-swap wrapper
# - push that container to the local tilt registry
# Once done, rebuilding now should be a lot faster since only the relevant
# binary is rebuilt and the hot swat wrapper takes care of the rest.
local_resource(
'crd-bootstrap-controller-binary',
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager ./',
deps = [
"main.go",
"go.mod",
"go.sum",
"api",
"controllers",
"pkg",
],
)

# Build the docker image for our controller. We use a specific Dockerfile
# since tilt can't run on a scratch container.
# `only` here is important, otherwise, the container will get updated
# on _any_ file change. We only want to monitor the binary.
# If debugging is enabled, we switch to a different docker file using
# the delve port.
entrypoint = ['/manager']
dockerfile = 'tilt.dockerfile'
docker_build_with_restart(
'ghcr.io/Skarlso/crd-bootstrap-controller',
'.',
dockerfile = dockerfile,
entrypoint = entrypoint,
only=[
'./bin',
],
live_update = [
sync('./bin/manager', '/manager'),
],
)
72 changes: 64 additions & 8 deletions api/v1alpha1/bootstrap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,78 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// GitHub defines a GitHub type source where the CRD is coming from `release` section of a GitHub repository.
type GitHub struct {
}

// ConfigMap defines a reference to a configmap which hold the CRD information. Version is taken from a version field.
type ConfigMap struct {
// +required
Name string `json:"name"`
// +required
Version string `json:"version"`
}

// URL holds a URL from which to fetch the CRD. Version is defined through the digest of the content.
type URL struct {
URL string `json:"url"`
}

// Source defines options from where to fetch CRD content.
type Source struct {
// +optional
GitHub *GitHub `json:"gitHub,omitempty"`
// +optional
ConfigMap *ConfigMap `json:"configMap,omitempty"`
// +optional
URL *URL `json:"url,omitempty"`
}

// BootstrapSpec defines the desired state of Bootstrap
type BootstrapSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Interval defines the regular interval at which a poll for new version should happen.
// +optional
Interval metav1.Time `json:"interval,omitempty"`

// SourceRef defines a reference to a source which will provide a CRD based on some contract.
// +required
Source *Source `json:"source"`

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

// BootstrapStatus defines the observed state of Bootstrap
type BootstrapStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// ObservedGeneration is the last reconciled generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// +optional
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""
Conditions []metav1.Condition `json:"conditions,omitempty"`

// +optional
LastAttemptedVersion string `json:"lastAttemptedVersion,omitempty"`

// +optional
LastAppliedVersion string `json:"lastAppliedVersion,omitempty"`

// +optional
LastAppliedDigest string `json:"lastAppliedDigest,omitempty"`
}

// GetConditions returns the conditions of the ComponentVersion.
func (in *Bootstrap) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

// SetConditions sets the conditions of the ComponentVersion.
func (in *Bootstrap) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

//+kubebuilder:object:root=true
Expand Down
93 changes: 91 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 0043b74

Please sign in to comment.