This repository was archived by the owner on Jun 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Resources override #362
Merged
knative-prow-robot
merged 5 commits into
knative:master
from
jcrossley3:resource-override
Mar 23, 2020
Merged
Resources override #362
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5883212
New field in CR, `resources`, to override deployments in manifest
jcrossley3 f2a0c2a
Use 0.13.0 manifest for some tests
jcrossley3 2601e2b
Unit tests for resource overrides
jcrossley3 fae8a4f
Change-of-plan: key by container name instead of deployment name
jcrossley3 93fedc5
Son of change-of-plan: no more default removal of resource reqs
jcrossley3 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| Copyright 2020 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| mf "github.com/manifestival/manifestival" | ||
| "go.uber.org/zap" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| v1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| servingv1alpha1 "knative.dev/serving-operator/pkg/apis/serving/v1alpha1" | ||
| ) | ||
|
|
||
| // ResourceRequirementsTransform configures the resource requests for | ||
| // all containers within all deployments in the manifest | ||
| func ResourceRequirementsTransform(instance *servingv1alpha1.KnativeServing, log *zap.SugaredLogger) mf.Transformer { | ||
| return func(u *unstructured.Unstructured) error { | ||
| if u.GetKind() == "Deployment" { | ||
| deployment := &appsv1.Deployment{} | ||
| if err := scheme.Scheme.Convert(u, deployment, nil); err != nil { | ||
| return err | ||
| } | ||
| containers := deployment.Spec.Template.Spec.Containers | ||
| for i := range containers { | ||
| if override := find(instance, containers[i].Name); override != nil { | ||
| merge(&override.Limits, &containers[i].Resources.Limits) | ||
| merge(&override.Requests, &containers[i].Resources.Requests) | ||
| } | ||
| } | ||
| if err := scheme.Scheme.Convert(deployment, u, nil); err != nil { | ||
| return err | ||
| } | ||
| // Avoid superfluous updates from converted zero defaults | ||
| u.SetCreationTimestamp(metav1.Time{}) | ||
| } | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func merge(src, tgt *v1.ResourceList) { | ||
| if len(*tgt) > 0 { | ||
| for k, v := range *src { | ||
| (*tgt)[k] = v | ||
| } | ||
| } else { | ||
| *tgt = *src | ||
| } | ||
| } | ||
|
|
||
| func find(instance *servingv1alpha1.KnativeServing, name string) *servingv1alpha1.ResourceRequirementsOverride { | ||
| for _, override := range instance.Spec.Resources { | ||
| if override.Container == name { | ||
| return &override | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.