Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Support custom MCAD container image #149

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ IMAGE_ORG_BASE ?= quay.io/project-codeflare
# codeflare.dev/codeflare-operator-bundle:$VERSION and codeflare.dev/codeflare-operator-catalog:$VERSION.
IMAGE_TAG_BASE ?= $(IMAGE_ORG_BASE)/codeflare-operator

# MCAD_IMAGE defines the default container image for the MCAD controller
MCAD_IMAGE ?= $(IMAGE_ORG_BASE)/mcad-controller:$(MCAD_REF)

# INSTASCALE_IMAGE defines the default container image for the InstaScale controller
INSTASCALE_IMAGE ?= $(IMAGE_ORG_BASE)/instascale-controller:$(INSTASCALE_VERSION)

Expand Down Expand Up @@ -117,6 +120,7 @@ defaults:
@echo "// ***********************" >> $(DEFAULTS_FILE)
@echo "" >> $(DEFAULTS_FILE)
@echo "const (" >> $(DEFAULTS_FILE)
@echo " MCADImage = \"$(MCAD_IMAGE)\"" >> $(DEFAULTS_FILE)
@echo " InstaScaleImage = \"$(INSTASCALE_IMAGE)\"" >> $(DEFAULTS_FILE)
@echo "" >> $(DEFAULTS_FILE)
@echo ")" >> $(DEFAULTS_FILE)
Expand Down
11 changes: 11 additions & 0 deletions api/codeflare/v1alpha1/mcad_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ type MCADSpec struct {
// ControllerResources defines the cpu and memory resource requirements for the MCAD Controller
// +kubebuilder:default={}
ControllerResources v1.ResourceRequirements `json:"controllerResources,omitempty" protobuf:"bytes,8,opt"`

// The container image for the MCAD controller deployment.
// If specified, the provided container image must be compatible with the running CodeFlare operator.
// Using an incompatible, or unrelated container image, will result in an undefined behavior.
// A CodeFlare operator upgrade will not upgrade the MCAD controller, that'll keep running this
// specified container image.
// If not specified, the latest version compatible with the running CodeFlare operator is used.
// A CodeFlare operator upgrade may upgrade the MCAD controller to a newer container image.
//
// +optional
ControllerImage string `json:"controllerImage,omitempty"`
}

// MCADStatus defines the observed state of MCAD
Expand Down
11 changes: 11 additions & 0 deletions config/crd/bases/codeflare.codeflare.dev_mcads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ spec:
description: AgentConfigs determine paths to agent config file:deploymentName
separated by commas(,).
type: string
controllerImage:
description: The container image for the MCAD controller deployment.
If specified, the provided container image must be compatible with
the running CodeFlare operator. Using an incompatible, or unrelated
container image, will result in an undefined behavior. A CodeFlare
operator upgrade will not upgrade the MCAD controller, that'll keep
running this specified container image. If not specified, the latest
version compatible with the running CodeFlare operator is used.
A CodeFlare operator upgrade may upgrade the MCAD controller to
a newer container image.
type: string
controllerResources:
description: ControllerResources defines the cpu and memory resource
requirements for the MCAD Controller
Expand Down
4 changes: 2 additions & 2 deletions config/internal/mcad/deployment.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ spec:
spec:
containers:
- name: mcad-controller
args: [ "--v", "4", "--logtostderr"]
args: ["--v", "4", "--logtostderr"]
command:
- mcad-controller
envFrom:
- configMapRef:
name: mcad-{{.Name}}-config
image: 'quay.io/project-codeflare/mcad-controller:release-v1.31.0'
image: {{.ControllerImage}}
imagePullPolicy: Always
ports:
- name: https
Expand Down
1 change: 1 addition & 0 deletions controllers/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ package controllers
// ***********************

const (
MCADImage = "quay.io/project-codeflare/mcad-controller:release-v1.31.0"
InstaScaleImage = "quay.io/project-codeflare/instascale-controller:v0.0.4"
)
8 changes: 2 additions & 6 deletions controllers/mcad_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ func (r *MCADReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
mcadCustomResource.APIVersion, mcadCustomResource.Kind = gvk.Version, gvk.Kind
}

err = params.ExtractParams(mcadCustomResource)
if err != nil {
log.Error(err, "Unable to parse MCAD custom resource")
return ctrl.Result{}, err
}
params.ExtractParams(mcadCustomResource)

if mcadCustomResource.ObjectMeta.DeletionTimestamp.IsZero() {
if !controllerutil.ContainsFinalizer(mcadCustomResource, finalizerName) {
Expand Down Expand Up @@ -189,7 +185,7 @@ func (r *MCADReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
if err != nil {
return ctrl.Result{}, err
}
err = r.Client.Status().Update(context.Background(), mcadCustomResource)
err = r.Client.Status().Update(ctx, mcadCustomResource)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
10 changes: 10 additions & 0 deletions controllers/mcad_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
mcadConfigMap2 = "./testdata/mcad_test_results/case_2/configmap.yaml"
mcadService2 = "./testdata/mcad_test_results/case_2/service.yaml"
mcadServiceAccount2 = "./testdata/mcad_test_results/case_2/serviceaccount.yaml"
mcadCRCase3 = "./testdata/mcad_test_cases/case_3.yaml"
mcadDeployment3 = "./testdata/mcad_test_results/case_3/deployment.yaml"
)

func deployMCAD(ctx context.Context, path string, opts mf.Option) {
Expand Down Expand Up @@ -54,4 +56,12 @@ var _ = Describe("The MCAD Controller", func() {
compareServices(mcadService2, opts)
})
})

Context("In a namespace, when a MCAD resource with a custom image is deployed", func() {

It("It should create a deployment", func() {
deployMCAD(ctx, mcadCRCase3, opts)
compareDeployments(mcadDeployment3, opts)
})
})
})
13 changes: 6 additions & 7 deletions controllers/mcad_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ type MCADParams struct {
QuotaRestURL string
PodCreationTimeout int
ControllerResources ControllerResources
ControllerImage string
}

// type ControllerResources struct {
// v1.ResourceRequirements
// }

// ExtractParams is currently a straight-up copy. We can add in more complex validation at a later date
func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) error {
func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) {
p.Name = mcad.Name
p.Namespace = mcad.Namespace
p.ControllerImage = mcad.Spec.ControllerImage
if p.ControllerImage == "" {
p.ControllerImage = MCADImage
}
p.Owner = mcad
p.EnableMonitoring = mcad.Spec.EnableMonitoring
p.MultiCluster = mcad.Spec.MultiCluster
Expand All @@ -52,6 +53,4 @@ func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) error {
p.QuotaRestURL = mcad.Spec.QuotaRestURL
p.PodCreationTimeout = mcad.Spec.PodCreationTimeout
p.ControllerResources = ControllerResources{mcad.Spec.ControllerResources}

return nil
}
6 changes: 6 additions & 0 deletions controllers/testdata/mcad_test_cases/case_3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: codeflare.codeflare.dev/v1alpha1
kind: MCAD
metadata:
name: custom-image
spec:
controllerImage: quay.io/project-codeflare/mcad-controller:custom
45 changes: 45 additions & 0 deletions controllers/testdata/mcad_test_results/case_3/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: mcad-controller-custom-image
namespace: default
labels:
app: mcad-custom-image
component: multi-cluster-application-dispatcher
spec:
replicas: 1
selector:
matchLabels:
app: mcad-custom-image
template:
metadata:
labels:
app: mcad-custom-image
component: multi-cluster-application-dispatcher
spec:
containers:
- name: mcad-controller
args: ["--v", "4", "--logtostderr"]
command:
- mcad-controller
envFrom:
- configMapRef:
name: mcad-custom-image-config
image: quay.io/project-codeflare/mcad-controller:custom
imagePullPolicy: Always
ports:
- name: https
containerPort: 6443
protocol: TCP
- name: http
containerPort: 8080
protocol: TCP
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- name: temp-vol
mountPath: /tmp
serviceAccountName: mcad-controller-custom-image
volumes:
- name: temp-vol
emptyDir: {}