Skip to content

Commit

Permalink
Remove environmentRequest dependency for Environment (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-persson authored Dec 3, 2024
1 parent 18368fa commit c07b4bd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/environment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type EnvironmentSpec struct {
// +kubebuilder:validation:Pattern="^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
Context string `json:"context"`

// +optional
Releaser *Image `json:"releaser,omitempty"`

Priority int `json:"priority"`
Tests []Test `json:"recipes"`
TestRunner string `json:"test_runner"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

13 changes: 13 additions & 0 deletions config/crd/bases/etos.eiffel-community.github.io_environments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ spec:
- testCase
type: object
type: array
releaser:
description: Image configuration.
properties:
image:
type: string
imagePullPolicy:
default: IfNotPresent
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
required:
- image
type: object
sub_suite_id:
pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
type: string
Expand Down
21 changes: 13 additions & 8 deletions internal/controller/environment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,17 @@ func (r *EnvironmentReconciler) reconcileReleaser(ctx context.Context, releasers
if releasers.empty() && !environment.ObjectMeta.DeletionTimestamp.IsZero() {
if controllerutil.ContainsFinalizer(environment, releaseFinalizer) {
logger.Info("Environment is being deleted, release it")
environmentRequest, err := r.environmentRequest(ctx, environment)
if err != nil {
return err
var image *etosv1alpha1.Image
if environment.Spec.Releaser != nil {
image = environment.Spec.Releaser
} else {
environmentRequest, err := r.environmentRequest(ctx, environment)
if err != nil {
return err
}
image = environmentRequest.Spec.Image
}
releaser := r.releaseJob(environment, environmentRequest)
fmt.Println(releaser)
releaser := r.releaseJob(environment, *image)
if err := ctrl.SetControllerReference(environment, releaser, r.Scheme); err != nil {
return err
}
Expand Down Expand Up @@ -236,7 +241,7 @@ func (r *EnvironmentReconciler) environmentRequest(ctx context.Context, environm
}

// releaseJob is the job definition for an environment releaser.
func (r EnvironmentReconciler) releaseJob(environment *etosv1alpha1.Environment, environmentRequest *etosv1alpha1.EnvironmentRequest) *batchv1.Job {
func (r EnvironmentReconciler) releaseJob(environment *etosv1alpha1.Environment, image etosv1alpha1.Image) *batchv1.Job {
id := environment.Labels["etos.eiffel-community.github.io/id"]
cluster := environment.Labels["etos.eiffel-community.github.io/cluster"]
ttl := int32(300)
Expand Down Expand Up @@ -269,8 +274,8 @@ func (r EnvironmentReconciler) releaseJob(environment *etosv1alpha1.Environment,
Containers: []corev1.Container{
{
Name: environment.Name,
Image: environmentRequest.Spec.Image.Image,
ImagePullPolicy: environmentRequest.Spec.ImagePullPolicy,
Image: image.Image,
ImagePullPolicy: image.ImagePullPolicy,
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("256Mi"),
Expand Down

0 comments on commit c07b4bd

Please sign in to comment.