Skip to content

Commit cf6855b

Browse files
committed
first version of environment controller
1 parent 87a7892 commit cf6855b

30 files changed

Lines changed: 8911 additions & 98 deletions

control-operator/Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.23 as builder
2+
FROM golang:1.25 as builder
33
ARG TARGETOS
44
ARG TARGETARCH
55
ARG MANAGER=task-manager
@@ -8,7 +8,6 @@ WORKDIR /workspace
88
# Copy the Go Modules manifests
99
COPY go.mod go.mod
1010
COPY go.sum go.sum
11-
RUN sed -i '\,replace github.com/AliceO2Group/Control,d' go.mod
1211
# cache deps before building and copying source so that we don't need to re-download as much
1312
# and so that source changes don't invalidate our downloaded layer
1413
RUN go mod download
@@ -17,8 +16,6 @@ RUN go mod download
1716
COPY cmd/ cmd/
1817
COPY api/ api/
1918
COPY internal/controller/ internal/controller/
20-
21-
RUN go mod download github.com/AliceO2Group/Control
2219
# Build
2320
# the GOARCH has not a default value to allow the binary be built according to the host where the command
2421
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO

control-operator/Makefile

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
2929
#
3030
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
3131
# alice.cern/operator-bundle:$VERSION and alice.cern/operator-catalog:$VERSION.
32-
IMAGE_TAG_BASE ?= teom/aliecs
32+
IMAGE_TAG_BASE ?= gitlab-registry.cern.ch/aliceo2group/dockerfiles/aliecs
3333

3434
# BUNDLE_IMG defines the image:tag used for the bundle.
3535
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36-
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
36+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)/bundle:v$(VERSION)
3737

3838
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
3939
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
@@ -51,8 +51,8 @@ endif
5151
OPERATOR_SDK_VERSION ?= unknown
5252

5353
# Image URL to use all building/pushing image targets
54-
TASK_IMG ?= docker.io/teom/aliecs-task-manager:latest
55-
ENVIRONMENT_IMG ?= docker.io/teom/aliecs-environment-manager:latest
54+
TASK_IMG ?= gitlab-registry.cern.ch/aliceo2group/dockerfiles/aliecs/task-manager:latest
55+
ENVIRONMENT_IMG ?= gitlab-registry.cern.ch/aliceo2group/dockerfiles/aliecs/environment-manager:latest
5656
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5757
ENVTEST_K8S_VERSION = 1.27.1
5858

@@ -98,11 +98,11 @@ help: ## Display this help.
9898

9999
.PHONY: manifests
100100
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
101-
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
102-
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
103-
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
104-
# However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
105-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
101+
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
102+
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
103+
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
104+
# However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
105+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
106106

107107
# .PHONY: manifests
108108
# manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
@@ -207,12 +207,20 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
207207
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
208208

209209
.PHONY: deploy
210-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
211-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
212-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f - --server-side
210+
deploy: deploy-task deploy-environment ## Deploy both controllers to the K8s cluster specified in ~/.kube/config.
211+
212+
.PHONY: deploy-task
213+
deploy-task: manifests kustomize ## Deploy task controller to the K8s cluster specified in ~/.kube/config.
214+
cd config/task && $(KUSTOMIZE) edit set image task-manager=${TASK_IMG}
215+
$(KUSTOMIZE) build config/task | $(KUBECTL) apply -f - --server-side
216+
217+
.PHONY: deploy-environment
218+
deploy-environment: manifests kustomize ## Deploy environment controller to the K8s cluster specified in ~/.kube/config.
219+
cd config/environment && $(KUSTOMIZE) edit set image environment-manager=${ENVIRONMENT_IMG}
220+
$(KUSTOMIZE) build config/environment | $(KUBECTL) apply -f - --server-side
213221

214222
.PHONY: undeploy
215-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
223+
undeploy: ## Undeploy both controllers from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
216224
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
217225

218226
##@ Build Dependencies
@@ -272,7 +280,8 @@ endif
272280
.PHONY: bundle
273281
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
274282
$(OPERATOR_SDK) generate kustomize manifests -q
275-
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
283+
cd config/manager && $(KUSTOMIZE) edit set image task-manager=$(TASK_IMG)
284+
cd config/manager && $(KUSTOMIZE) edit set image environment-manager=$(ENVIRONMENT_IMG)
276285
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
277286
$(OPERATOR_SDK) bundle validate ./bundle
278287

@@ -306,7 +315,7 @@ endif
306315
BUNDLE_IMGS ?= $(BUNDLE_IMG)
307316

308317
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
309-
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
318+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)/catalog:v$(VERSION)
310319

311320
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
312321
ifneq ($(origin CATALOG_BASE_IMG), undefined)

control-operator/api/v1alpha1/environment_types.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,23 @@
2525
package v1alpha1
2626

2727
import (
28+
v1 "k8s.io/api/core/v1"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
)
3031

3132
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
3233
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
3334

34-
type TaskDefinition struct{}
35-
3635
// EnvironmentSpec defines the desired state of Environment
3736
type EnvironmentSpec struct {
3837
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3938
// Important: Run "make" to regenerate code after modifying this file
4039
// The following markers will use OpenAPI v3 schema to validate the value
4140
// More info: https://book.kubebuilder.io/reference/markers/crd-validation.html
4241

43-
// foo is an example field of Environment. Edit environment_types.go to remove/update
44-
Tasks map[string][]Task `json:"tasks"`
42+
Tasks map[string][]TaskTemplate `json:"tasks"`
4543
// +kubebuilder:validation:Enum=standby;deployed;configured;running
46-
State string `json:"state,omitempty"`
44+
State string `json:"state"`
4745
}
4846

4947
// EnvironmentStatus defines the observed state of Environment.
@@ -53,7 +51,6 @@ type EnvironmentStatus struct {
5351

5452
// For Kubernetes API conventions, see:
5553
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
56-
5754
// conditions represent the current state of the Environment resource.
5855
// Each condition has a unique type and reflects the status of a specific aspect of the resource.
5956
//
@@ -66,14 +63,28 @@ type EnvironmentStatus struct {
6663
// +listType=map
6764
// +listMapKey=type
6865
// +optional
69-
Conditions []metav1.Condition `json:"conditions,omitempty"`
70-
Tasks map[string][]TaskTemplate `json:"tasks"`
71-
// +kubebuilder:validation:Enum=standby;deployed;configured;running
72-
State string `json:"state,omitempty"`
66+
Conditions []metav1.Condition `json:"conditions,omitempty"`
67+
68+
Tasks map[string]map[string]string `json:"tasks"`
69+
State string `json:"state,omitempty"`
70+
}
71+
72+
type TaskReference struct {
73+
Name string `json:"name"`
74+
Env []v1.EnvVar `json:"env"`
75+
ArgsCLI []string `json:"argsCLI"`
76+
ArgsTransition map[string]string `json:"argsTransition"`
77+
}
78+
79+
type TemplateSpecification struct {
80+
Tasks map[string][]TaskReference `json:"tasks"`
7381
}
7482

7583
// +kubebuilder:object:root=true
7684
// +kubebuilder:subresource:status
85+
// +kubebuilder:printcolumn:name="Desired",type="string",JSONPath=".spec.state"
86+
// +kubebuilder:printcolumn:name="Actual",type="string",JSONPath=".status.state"
87+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
7788

7889
// Environment is the Schema for the environments API
7990
type Environment struct {
@@ -83,6 +94,11 @@ type Environment struct {
8394
// +optional
8495
metav1.ObjectMeta `json:"metadata,omitzero"`
8596

97+
// taskTemplates defines templates stored in cluster to be used
98+
// for task creation, meant for more common tasks
99+
// +optional
100+
TaskTemplates TemplateSpecification `json:"taskTemplates"`
101+
86102
// spec defines the desired state of Environment
87103
// +required
88104
Spec EnvironmentSpec `json:"spec"`

control-operator/api/v1alpha1/zz_generated.deepcopy.go

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

control-operator/cmd/task-manager/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func main() {
5656
var metricsAddr string
5757
var enableLeaderElection bool
5858
var probeAddr string
59-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":9080", "The address the metric endpoint binds to.")
60-
flag.StringVar(&probeAddr, "health-probe-bind-address", ":9081", "The address the probe endpoint binds to.")
59+
flag.StringVar(&metricsAddr, "metrics-bind-address", ":9082", "The address the metric endpoint binds to.")
60+
flag.StringVar(&probeAddr, "health-probe-bind-address", ":9083", "The address the probe endpoint binds to.")
6161
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6262
"Enable leader election for controller manager. "+
6363
"Enabling this will ensure there is only one active controller manager.")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- namespace.yaml
6+
- ../crd
7+
- ../rbac
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
app.kubernetes.io/name: namespace
7+
app.kubernetes.io/instance: system
8+
app.kubernetes.io/component: manager
9+
app.kubernetes.io/created-by: operator
10+
app.kubernetes.io/part-of: operator
11+
app.kubernetes.io/managed-by: kustomize
12+
name: system

0 commit comments

Comments
 (0)