Skip to content

feat: disable image validation webhook, requeue pool if no image found #76

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

Merged
merged 6 commits into from
Jan 23, 2024
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
31 changes: 0 additions & 31 deletions api/v1alpha1/pool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ func (r *Pool) ValidateCreate() (admission.Warnings, error) {
poollog.Info("validate create", "name", r.Name)
ctx := context.TODO()

err := validateImageName(ctx, r)
if err != nil {
return nil, apierrors.NewInvalid(
schema.GroupKind{Group: GroupVersion.Group, Kind: "Pool"},
r.Name,
field.ErrorList{err},
)
}

if err := r.validateExtraSpec(); err != nil {
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Pool"},
r.Name,
Expand Down Expand Up @@ -94,15 +85,6 @@ func (r *Pool) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {

// if the object is being deleted, skip validation
if r.GetDeletionTimestamp() == nil {
err := validateImageName(context.Background(), r)
if err != nil {
return nil, apierrors.NewInvalid(
schema.GroupKind{Group: GroupVersion.Group, Kind: "Pool"},
r.Name,
field.ErrorList{err},
)
}

if err := r.validateExtraSpec(); err != nil {
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Pool"},
r.Name,
Expand Down Expand Up @@ -130,19 +112,6 @@ func (r *Pool) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
return nil, nil
}

func validateImageName(ctx context.Context, r *Pool) *field.Error {
image := Image{}
err := c.Get(ctx, client.ObjectKey{Name: r.Spec.ImageName, Namespace: r.Namespace}, &image)
if err != nil {
return field.Invalid(
field.NewPath("spec").Child("imageName"),
r.Spec.ImageName,
err.Error(),
)
}
return nil
}

func (r *Pool) validateProviderName(old *Pool) *field.Error {
poollog.Info("validate spec.providerName", "spec.providerName", r.Spec.ProviderName)
fieldPath := field.NewPath("spec").Child("providerName")
Expand Down
31 changes: 9 additions & 22 deletions internal/controller/pool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ func (r *PoolReconciler) reconcileUpdate(ctx context.Context, garmClient garmCli
WithName("reconcileUpdate")
log.Info("pool on garm side found", "id", pool.Status.ID, "name", pool.Name)

poolNeedsUpdate, runners, err := r.comparePoolSpecs(ctx, pool, garmClient)
image, err := r.getImage(ctx, pool)
if err != nil {
return r.handleUpdateError(ctx, pool, err)
}

poolNeedsUpdate, runners, err := r.comparePoolSpecs(ctx, pool, image.Spec.Tag, garmClient)
if err != nil {
log.Error(err, "error comparing pool specs")
return r.handleUpdateError(ctx, pool, err)
Expand All @@ -160,12 +165,6 @@ func (r *PoolReconciler) reconcileUpdate(ctx context.Context, garmClient garmCli
if !poolNeedsUpdate {
log.Info("pool CR differs from pool on garm side. Trigger a garm pool update")

image, err := r.getImage(ctx, pool)
if err != nil {
log.Error(err, "error getting image")
return r.handleUpdateError(ctx, pool, err)
}

if err = poolUtil.UpdatePool(ctx, garmClient, pool, image); err != nil {
log.Error(err, "error updating pool")
return r.handleUpdateError(ctx, pool, err)
Expand Down Expand Up @@ -221,13 +220,7 @@ func (r *PoolReconciler) reconcileDelete(ctx context.Context, garmClient garmCli
return r.handleUpdateError(ctx, pool, err)
}

image, err := r.getImage(ctx, pool)
if err != nil {
log.Error(err, "error getting image")
return r.handleUpdateError(ctx, pool, err)
}

if err = poolUtil.UpdatePool(ctx, garmClient, pool, image); err != nil {
if err := poolUtil.UpdatePool(ctx, garmClient, pool, nil); err != nil {
log.Error(err, "error updating pool")
return r.handleUpdateError(ctx, pool, err)
}
Expand Down Expand Up @@ -336,16 +329,10 @@ func (r *PoolReconciler) ensureFinalizer(ctx context.Context, pool *garmoperator
return nil
}

func (r *PoolReconciler) comparePoolSpecs(ctx context.Context, pool *garmoperatorv1alpha1.Pool, poolClient garmClient.PoolClient) (bool, []params.Instance, error) {
func (r *PoolReconciler) comparePoolSpecs(ctx context.Context, pool *garmoperatorv1alpha1.Pool, imageTag string, poolClient garmClient.PoolClient) (bool, []params.Instance, error) {
log := log.FromContext(ctx).
WithName("comparePoolSpecs")

image, err := r.getImage(ctx, pool)
if err != nil {
log.Error(err, "error getting image")
return false, []params.Instance{}, err
}

gitHubScopeRef, err := r.fetchGitHubScopeCRD(ctx, pool)
if err != nil {
log.Error(err, "error fetching GitHubScopeRef")
Expand Down Expand Up @@ -379,7 +366,7 @@ func (r *PoolReconciler) comparePoolSpecs(ctx context.Context, pool *garmoperato
},
MaxRunners: pool.Spec.MaxRunners,
MinIdleRunners: pool.Spec.MinIdleRunners,
Image: image.Spec.Tag,
Image: imageTag,
Flavor: pool.Spec.Flavor,
OSType: pool.Spec.OSType,
OSArch: pool.Spec.OSArch,
Expand Down
Loading