Skip to content

Commit cd0cd54

Browse files
astefanuttiopenshift-merge-robot
authored andcommitted
feat(api): Support custom MCAD container image
1 parent 9a7746b commit cd0cd54

File tree

10 files changed

+98
-15
lines changed

10 files changed

+98
-15
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ IMAGE_ORG_BASE ?= quay.io/project-codeflare
4848
# codeflare.dev/codeflare-operator-bundle:$VERSION and codeflare.dev/codeflare-operator-catalog:$VERSION.
4949
IMAGE_TAG_BASE ?= $(IMAGE_ORG_BASE)/codeflare-operator
5050

51+
# MCAD_IMAGE defines the default container image for the MCAD controller
52+
MCAD_IMAGE ?= $(IMAGE_ORG_BASE)/mcad-controller:$(MCAD_REF)
53+
5154
# INSTASCALE_IMAGE defines the default container image for the InstaScale controller
5255
INSTASCALE_IMAGE ?= $(IMAGE_ORG_BASE)/instascale-controller:$(INSTASCALE_VERSION)
5356

@@ -117,6 +120,7 @@ defaults:
117120
@echo "// ***********************" >> $(DEFAULTS_FILE)
118121
@echo "" >> $(DEFAULTS_FILE)
119122
@echo "const (" >> $(DEFAULTS_FILE)
123+
@echo " MCADImage = \"$(MCAD_IMAGE)\"" >> $(DEFAULTS_FILE)
120124
@echo " InstaScaleImage = \"$(INSTASCALE_IMAGE)\"" >> $(DEFAULTS_FILE)
121125
@echo "" >> $(DEFAULTS_FILE)
122126
@echo ")" >> $(DEFAULTS_FILE)

api/codeflare/v1alpha1/mcad_types.go

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ type MCADSpec struct {
5353
// ControllerResources defines the cpu and memory resource requirements for the MCAD Controller
5454
// +kubebuilder:default={}
5555
ControllerResources v1.ResourceRequirements `json:"controllerResources,omitempty" protobuf:"bytes,8,opt"`
56+
57+
// The container image for the MCAD controller deployment.
58+
// If specified, the provided container image must be compatible with the running CodeFlare operator.
59+
// Using an incompatible, or unrelated container image, will result in an undefined behavior.
60+
// A CodeFlare operator upgrade will not upgrade the MCAD controller, that'll keep running this
61+
// specified container image.
62+
// If not specified, the latest version compatible with the running CodeFlare operator is used.
63+
// A CodeFlare operator upgrade may upgrade the MCAD controller to a newer container image.
64+
//
65+
// +optional
66+
ControllerImage string `json:"controllerImage,omitempty"`
5667
}
5768

5869
// MCADStatus defines the observed state of MCAD

config/crd/bases/codeflare.codeflare.dev_mcads.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ spec:
3939
description: AgentConfigs determine paths to agent config file:deploymentName
4040
separated by commas(,).
4141
type: string
42+
controllerImage:
43+
description: The container image for the MCAD controller deployment.
44+
If specified, the provided container image must be compatible with
45+
the running CodeFlare operator. Using an incompatible, or unrelated
46+
container image, will result in an undefined behavior. A CodeFlare
47+
operator upgrade will not upgrade the MCAD controller, that'll keep
48+
running this specified container image. If not specified, the latest
49+
version compatible with the running CodeFlare operator is used.
50+
A CodeFlare operator upgrade may upgrade the MCAD controller to
51+
a newer container image.
52+
type: string
4253
controllerResources:
4354
description: ControllerResources defines the cpu and memory resource
4455
requirements for the MCAD Controller

config/internal/mcad/deployment.yaml.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ spec:
1919
spec:
2020
containers:
2121
- name: mcad-controller
22-
args: [ "--v", "4", "--logtostderr"]
22+
args: ["--v", "4", "--logtostderr"]
2323
command:
2424
- mcad-controller
2525
envFrom:
2626
- configMapRef:
2727
name: mcad-{{.Name}}-config
28-
image: 'quay.io/project-codeflare/mcad-controller:release-v1.31.0'
28+
image: {{.ControllerImage}}
2929
imagePullPolicy: Always
3030
ports:
3131
- name: https

controllers/defaults.go

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ package controllers
55
// ***********************
66

77
const (
8+
MCADImage = "quay.io/project-codeflare/mcad-controller:release-v1.31.0"
89
InstaScaleImage = "quay.io/project-codeflare/instascale-controller:v0.0.4"
910
)

controllers/mcad_controller.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ func (r *MCADReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
151151
mcadCustomResource.APIVersion, mcadCustomResource.Kind = gvk.Version, gvk.Kind
152152
}
153153

154-
err = params.ExtractParams(mcadCustomResource)
155-
if err != nil {
156-
log.Error(err, "Unable to parse MCAD custom resource")
157-
return ctrl.Result{}, err
158-
}
154+
params.ExtractParams(mcadCustomResource)
159155

160156
if mcadCustomResource.ObjectMeta.DeletionTimestamp.IsZero() {
161157
if !controllerutil.ContainsFinalizer(mcadCustomResource, finalizerName) {
@@ -189,7 +185,7 @@ func (r *MCADReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
189185
if err != nil {
190186
return ctrl.Result{}, err
191187
}
192-
err = r.Client.Status().Update(context.Background(), mcadCustomResource)
188+
err = r.Client.Status().Update(ctx, mcadCustomResource)
193189
if err != nil {
194190
return ctrl.Result{}, err
195191
}

controllers/mcad_controller_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
mcadConfigMap2 = "./testdata/mcad_test_results/case_2/configmap.yaml"
2222
mcadService2 = "./testdata/mcad_test_results/case_2/service.yaml"
2323
mcadServiceAccount2 = "./testdata/mcad_test_results/case_2/serviceaccount.yaml"
24+
mcadCRCase3 = "./testdata/mcad_test_cases/case_3.yaml"
25+
mcadDeployment3 = "./testdata/mcad_test_results/case_3/deployment.yaml"
2426
)
2527

2628
func deployMCAD(ctx context.Context, path string, opts mf.Option) {
@@ -54,4 +56,12 @@ var _ = Describe("The MCAD Controller", func() {
5456
compareServices(mcadService2, opts)
5557
})
5658
})
59+
60+
Context("In a namespace, when a MCAD resource with a custom image is deployed", func() {
61+
62+
It("It should create a deployment", func() {
63+
deployMCAD(ctx, mcadCRCase3, opts)
64+
compareDeployments(mcadDeployment3, opts)
65+
})
66+
})
5767
})

controllers/mcad_params.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ type MCADParams struct {
3333
QuotaRestURL string
3434
PodCreationTimeout int
3535
ControllerResources ControllerResources
36+
ControllerImage string
3637
}
3738

38-
// type ControllerResources struct {
39-
// v1.ResourceRequirements
40-
// }
41-
4239
// ExtractParams is currently a straight-up copy. We can add in more complex validation at a later date
43-
func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) error {
40+
func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) {
4441
p.Name = mcad.Name
4542
p.Namespace = mcad.Namespace
43+
p.ControllerImage = mcad.Spec.ControllerImage
44+
if p.ControllerImage == "" {
45+
p.ControllerImage = MCADImage
46+
}
4647
p.Owner = mcad
4748
p.EnableMonitoring = mcad.Spec.EnableMonitoring
4849
p.MultiCluster = mcad.Spec.MultiCluster
@@ -52,6 +53,4 @@ func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) error {
5253
p.QuotaRestURL = mcad.Spec.QuotaRestURL
5354
p.PodCreationTimeout = mcad.Spec.PodCreationTimeout
5455
p.ControllerResources = ControllerResources{mcad.Spec.ControllerResources}
55-
56-
return nil
5756
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: codeflare.codeflare.dev/v1alpha1
2+
kind: MCAD
3+
metadata:
4+
name: custom-image
5+
spec:
6+
controllerImage: quay.io/project-codeflare/mcad-controller:custom
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
kind: Deployment
2+
apiVersion: apps/v1
3+
metadata:
4+
name: mcad-controller-custom-image
5+
namespace: default
6+
labels:
7+
app: mcad-custom-image
8+
component: multi-cluster-application-dispatcher
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app: mcad-custom-image
14+
template:
15+
metadata:
16+
labels:
17+
app: mcad-custom-image
18+
component: multi-cluster-application-dispatcher
19+
spec:
20+
containers:
21+
- name: mcad-controller
22+
args: ["--v", "4", "--logtostderr"]
23+
command:
24+
- mcad-controller
25+
envFrom:
26+
- configMapRef:
27+
name: mcad-custom-image-config
28+
image: quay.io/project-codeflare/mcad-controller:custom
29+
imagePullPolicy: Always
30+
ports:
31+
- name: https
32+
containerPort: 6443
33+
protocol: TCP
34+
- name: http
35+
containerPort: 8080
36+
protocol: TCP
37+
terminationMessagePath: /dev/termination-log
38+
terminationMessagePolicy: File
39+
volumeMounts:
40+
- name: temp-vol
41+
mountPath: /tmp
42+
serviceAccountName: mcad-controller-custom-image
43+
volumes:
44+
- name: temp-vol
45+
emptyDir: {}

0 commit comments

Comments
 (0)