Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

MutatingAdmissionWebhook for relocating image references #37

Closed
wants to merge 5 commits into from
Closed

MutatingAdmissionWebhook for relocating image references #37

wants to merge 5 commits into from

Conversation

glyn
Copy link
Contributor

@glyn glyn commented Sep 25, 2019

@codecov
Copy link

codecov bot commented Sep 25, 2019

Codecov Report

Merging #37 into master will increase coverage by 5.66%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #37      +/-   ##
==========================================
+ Coverage   68.12%   73.79%   +5.66%     
==========================================
  Files           8        9       +1     
  Lines         342      416      +74     
==========================================
+ Hits          233      307      +74     
  Misses         95       95              
  Partials       14       14
Impacted Files Coverage Δ
pkg/multimap/composite.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28a4e87...66043b0. Read the comment docs.

@glyn
Copy link
Contributor Author

glyn commented Sep 30, 2019

TODO: add namespaceSelector so that the webhook doesn't apply to itself. Without this, the following can occur if the webhook is created before the underlying service:

Warning  FailedCreate  36s (x15 over 118s)  replicaset-controller  Error creating: Internal error occurred: failed calling webhook "image-relocating-webhook.image-relocation.pivotal.io": Post https://ir-webhook.image-relocation.svc:443/image-relocation?timeout=30s: no endpoints available for service "ir-webhook"

(Thanks @scothis who spotted this.)

@glyn
Copy link
Contributor Author

glyn commented Oct 2, 2019

TODO: add namespaceSelector so that the webhook doesn't apply to itself. Without this, the following can occur if the webhook is created before the underlying service:

Warning  FailedCreate  36s (x15 over 118s)  replicaset-controller  Error creating: Internal error occurred: failed calling webhook "image-relocating-webhook.image-relocation.pivotal.io": Post https://ir-webhook.image-relocation.svc:443/image-relocation?timeout=30s: no endpoints available for service "ir-webhook"

(Thanks @scothis who spotted this.)

Done.

@glyn glyn marked this pull request as ready for review October 2, 2019 11:21
@glyn glyn self-assigned this Oct 2, 2019
@glyn glyn requested a review from scothis October 2, 2019 11:26
Copy link

@scothis scothis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CRD semantics will take a couple more iterations to get right. There are a number of corner cases that don't appear to have consistent defined semantics.

A simpler alternative, would be a single ConfigMap that is mounted in the webhook. This would sidestep reconciling the CRD resources to a single map.

Other questions/comments are inline. Happy to voice on anything that may be confusing.

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: imagemaps.webhook.image-relocation.pivotal.io
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webhook is an implementation detail. - should generally be avoided in api groups.

Suggested change
name: imagemaps.webhook.image-relocation.pivotal.io
name: imagemaps.imagerelocation.pivotal.io

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, but kept the - for readability.

metadata:
name: ir-cluster-role
rules:
- apiGroups: ["*"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we lock this down to the exact permissions needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I'll need to investigate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a FIXME comment for now.

names:
plural: imagemaps
singular: imagemap
kind: ImageMap
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cluster scoped resources, should be use Cluster as a prefix

Suggested change
kind: ImageMap
kind: ClusterImageMap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopted.

config/samples/webhook_v1alpha1_imagemap.yaml Show resolved Hide resolved
Map map[string]string `json:"map,omitempty"`
}

func (in *ImageMapSpec) DeepCopyInto(out *ImageMapSpec) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeepCopy methods are typically generated and put into a separate file (zz_generated.deepcopy.go) so they can be updated without impacting the main source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the generated methods in such a file but had to add these manually.


// ImageMapStatus defines the observed state of ImageMap
type ImageMapStatus struct {
Map map[string]string `json:"map,omitempty"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these values any different than the spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Is that a problem?

pkg/controller/imagemap_controller.go Show resolved Hide resolved
pkg/multimap/composite.go Show resolved Hide resolved
pkg/multimap/composite.go Show resolved Hide resolved
return admission.Errored(http.StatusBadRequest, fmt.Errorf("decoding pod: %s", err))
}
} else {
err := i.client.Get(ctx, types.NamespacedName{Namespace: req.Namespace, Name: req.Name}, &pod)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can you get a resource from the API Server that hasn't been created yet? I know this isn't original code, I'm just noticing it now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I was nervous about ripping this code out. I'll check with @cppforlife.

@glyn
Copy link
Contributor Author

glyn commented Oct 3, 2019

The CRD semantics will take a couple more iterations to get right. There are a number of corner cases that don't appear to have consistent defined semantics.

I don't think you detailed the corner cases inline. Please could you elaborate?

A simpler alternative, would be a single ConfigMap that is mounted in the webhook. This would sidestep reconciling the CRD resources to a single map.

This doesn't feel particularly scalable. For instance, if more than one bundle was relocated by different people, they'd have to coordinate to merge the relocation mappings into the single ConfigMap. Plus they'd need to handle any inconsistencies manually.

Other questions/comments are inline. Happy to voice on anything that may be confusing.

Thanks!

@glyn
Copy link
Contributor Author

glyn commented Oct 17, 2019

Closing as the plan is to put the webhook in its own repository (https://github.com/pivotal/kubernetes-image-mapper), starting with vmware-archive/kubernetes-image-mapper#2.

@glyn glyn closed this Oct 17, 2019
glyn added a commit to vmware-archive/kubernetes-image-mapper that referenced this pull request Nov 20, 2019
Based on the spike in vmware-archive/image-relocation#37.

Deleted controllers/suite_test.go until we are ready to add an integration test.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a MutatingAdmissionWebhook to apply relocation mappings to pods
2 participants