-
Notifications
You must be signed in to change notification settings - Fork 137
Add a MutatingAdmissionWebook + Defaulting/Validation for MachineDeployment #362
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
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
04a2c57
Initial plumbing
alvaroaleman d79d9fd
Full plumbing
alvaroaleman 4fdf143
Add business logic to machineDeployment defaulting and validation
alvaroaleman e0e5677
Check for len(errs) not fore != nil
alvaroaleman fdfdedf
Only create a jsonpatch if there were changes
alvaroaleman d425446
Use evanphx/json-patch, hopefully not buggy
alvaroaleman 310f1be
Test
alvaroaleman 09af17f
Revert back to mattbairds jsonpatch library
alvaroaleman 340a9bd
Add some debug logging
alvaroaleman ae4db04
Update e2e testing to use MatatingAdmissionWebhook
alvaroaleman 5402daf
Merge branch 'master' into admission-webhook
alvaroaleman 74c81a9
Increase size of e2e controlller to check if it helps
alvaroaleman 4b7aef7
Use ipvs on kubeadm-controller in e2e tests
alvaroaleman c03b573
Revert "Use ipvs on kubeadm-controller in e2e tests"
alvaroaleman 69a36e7
Move webhook into a dedicated app
alvaroaleman 2a3e150
Move webhook into a dedicated deployment
alvaroaleman 505a06a
Fix name of service
alvaroaleman 181ae61
Block webhook shutdown
alvaroaleman a44c132
Use one replica for the webhook
alvaroaleman 2734863
Small fixes
alvaroaleman b569ac6
Clean up unneeded temporal changes
alvaroaleman 62c7555
Fix docker-image target
alvaroaleman 1af777f
Fix test if machine-controller is running
alvaroaleman b981212
Use one docker image for everything
alvaroaleman 278030e
Merge branch 'master' into admission-webhook
alvaroaleman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
|
|
||
| "github.com/golang/glog" | ||
|
|
||
| "github.com/kubermatic/machine-controller/pkg/admission" | ||
| ) | ||
|
|
||
| var ( | ||
| admissionListenAddress string | ||
| admissionTLSCertPath string | ||
| admissionTLSKeyPath string | ||
| ) | ||
|
|
||
| func main() { | ||
| flag.StringVar(&admissionListenAddress, "listen-address", ":9876", "The address on which the MutatingWebhook will listen on") | ||
| flag.StringVar(&admissionTLSCertPath, "tls-cert-path", "/tmp/cert/cert.pem", "The path of the TLS cert for the MutatingWebhook") | ||
| flag.StringVar(&admissionTLSKeyPath, "tls-key-path", "/tmp/cert/key.pem", "The path of the TLS key for the MutatingWebhook") | ||
| flag.Parse() | ||
|
|
||
| s := admission.New(admissionListenAddress) | ||
| if err := s.ListenAndServeTLS(admissionTLSCertPath, admissionTLSKeyPath); err != nil { | ||
| glog.Fatalf("Failed to start server: %v", err) | ||
| } | ||
| defer func() { | ||
| if err := s.Close(); err != nil { | ||
| glog.Fatalf("Failed to shutdown server: %v", err) | ||
| } | ||
| }() | ||
| glog.Infof("Listening on %s", admissionListenAddress) | ||
| select {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package admission | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "reflect" | ||
| "time" | ||
|
|
||
| "github.com/golang/glog" | ||
| "github.com/mattbaird/jsonpatch" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
| ) | ||
|
|
||
| func New(listenAddress string) *http.Server { | ||
| m := http.NewServeMux() | ||
| m.HandleFunc("/machinedeployments", handleFuncFactory(mutateMachineDeployments)) | ||
| m.HandleFunc("/healthz", healthZHandler) | ||
| return &http.Server{ | ||
| Addr: listenAddress, | ||
| Handler: m, | ||
| ReadTimeout: 5 * time.Second, | ||
| WriteTimeout: 10 * time.Second, | ||
| } | ||
| } | ||
|
|
||
| func healthZHandler(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| } | ||
|
|
||
| func newJSONPatch(original, current runtime.Object) ([]jsonpatch.JsonPatchOperation, error) { | ||
| originalGVK := original.GetObjectKind().GroupVersionKind() | ||
| currentGVK := current.GetObjectKind().GroupVersionKind() | ||
| if !reflect.DeepEqual(originalGVK, currentGVK) { | ||
| return nil, fmt.Errorf("GroupVersionKind %#v is expected to match %#v", originalGVK, currentGVK) | ||
| } | ||
| ori, err := json.Marshal(original) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| glog.V(4).Infof("jsonpatch: Marshaled original: %s", string(ori)) | ||
| cur, err := json.Marshal(current) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| glog.V(4).Infof("jsonpatch: Marshaled target: %s", string(cur)) | ||
| return jsonpatch.CreatePatch(ori, cur) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until I put this into a dedicated Deployment, the e2e tests always had some failures because of a connection reset when the APIServer tried to call the Webhook