Skip to content

Commit

Permalink
wip: only override deployment resources when explicitly defined in su…
Browse files Browse the repository at this point in the history
…bscription.spec.config

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
  • Loading branch information
joelanford committed Feb 16, 2021
1 parent 31c1c56 commit 87f78f7
Show file tree
Hide file tree
Showing 40 changed files with 1,129 additions and 487 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ run-console-local:
uninstall:
@echo Uninstalling OLM:
- kubectl delete -f deploy/upstream/quickstart/crds.yaml
- kubectl delete -f deploy/upstream/quickstart/olm.yam
- kubectl delete -f deploy/upstream/quickstart/olm.yaml
- kubectl delete catalogsources.operators.coreos.com
- kubectl delete clusterserviceversions.operators.coreos.com
- kubectl delete installplans.operators.coreos.com
Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ require (
google.golang.org/grpc v1.30.0
gopkg.in/yaml.v2 v2.3.0
helm.sh/helm/v3 v3.1.0-rc.1.0.20201215141456-e71d38b414eb
k8s.io/api v0.20.0
k8s.io/apiextensions-apiserver v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/apiserver v0.20.0
k8s.io/client-go v0.20.0
k8s.io/code-generator v0.20.0
k8s.io/component-base v0.20.0
k8s.io/api v0.20.1
k8s.io/apiextensions-apiserver v0.20.1
k8s.io/apimachinery v0.20.1
k8s.io/apiserver v0.20.1
k8s.io/client-go v0.20.1
k8s.io/code-generator v0.20.1
k8s.io/component-base v0.20.1
k8s.io/klog v1.0.0
k8s.io/kube-aggregator v0.20.0
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.7.0
sigs.k8s.io/controller-runtime v0.8.0
sigs.k8s.io/controller-tools v0.4.1
sigs.k8s.io/kind v0.7.0
)
Expand All @@ -64,6 +64,8 @@ replace (
github.com/openshift/api => github.com/openshift/api v0.0.0-20200331152225-585af27e34fd // release-4.5
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 // release-4.5

github.com/operator-framework/api => github.com/joelanford/api v0.0.0-20210216180012-67617936c73e

// pinned because latest etcd does not yet work with the latest grpc version (1.30.0)
go.etcd.io/etcd => go.etcd.io/etcd v0.5.0-alpha.5.0.20200520232829-54ba9589114f
google.golang.org/grpc => google.golang.org/grpc v1.27.0
Expand Down
58 changes: 16 additions & 42 deletions go.sum

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions pkg/controller/operators/olm/overrides/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type operatorConfig struct {
logger *logrus.Logger
}

func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOverrides []corev1.EnvVar, volumeOverrides []corev1.Volume, volumeMountOverrides []corev1.VolumeMount, tolerationOverrides []corev1.Toleration, resourcesOverride corev1.ResourceRequirements, nodeSelectorOverride map[string]string, err error) {
func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOverrides []corev1.EnvVar, volumeOverrides []corev1.Volume, volumeMountOverrides []corev1.VolumeMount, tolerationOverrides []corev1.Toleration, resourcesOverride *corev1.ResourceRequirements, nodeSelectorOverride map[string]string, err error) {
list, listErr := o.lister.OperatorsV1alpha1().SubscriptionLister().Subscriptions(ownerCSV.GetNamespace()).List(labels.Everything())
if listErr != nil {
err = fmt.Errorf("failed to list subscription namespace=%s - %v", ownerCSV.GetNamespace(), listErr)
Expand All @@ -29,12 +29,14 @@ func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOve
return
}

envVarOverrides = owner.Spec.Config.Env
volumeOverrides = owner.Spec.Config.Volumes
volumeMountOverrides = owner.Spec.Config.VolumeMounts
tolerationOverrides = owner.Spec.Config.Tolerations
resourcesOverride = owner.Spec.Config.Resources
nodeSelectorOverride = owner.Spec.Config.NodeSelector
if owner.Spec.Config != nil {
envVarOverrides = owner.Spec.Config.Env
volumeOverrides = owner.Spec.Config.Volumes
volumeMountOverrides = owner.Spec.Config.VolumeMounts
tolerationOverrides = owner.Spec.Config.Tolerations
resourcesOverride = owner.Spec.Config.Resources
nodeSelectorOverride = owner.Spec.Config.NodeSelector
}

return
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/operators/olm/overrides/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,18 @@ func findToleration(tolerations []corev1.Toleration, toleration corev1.Toleratio
// into given podSpec
//
// If podSpec already defines Resources, it will be overwritten
func InjectResourcesIntoDeployment(podSpec *corev1.PodSpec, resources corev1.ResourceRequirements) error {
func InjectResourcesIntoDeployment(podSpec *corev1.PodSpec, resources *corev1.ResourceRequirements) error {
if podSpec == nil {
return errors.New("no pod spec provided")
}

if resources == nil {
return nil
}

for i := range podSpec.Containers {
container := &podSpec.Containers[i]
container.Resources = resources
container.Resources = *resources
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/operators/olm/overrides/inject/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,25 +631,25 @@ func TestInjectResourcesIntoDeployment(t *testing.T) {
tests := []struct {
name string
podSpec *corev1.PodSpec
resources corev1.ResourceRequirements
resources *corev1.ResourceRequirements
expected *corev1.PodSpec
}{
{
// PodSpec has one container and empty resources
// Expected: Resources will remain empty
name: "WithEmptyResources",
// PodSpec has one container and existing resources
// Expected: PodSpec resources will remain untouched
name: "WithNilResources",
podSpec: &corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Resources: corev1.ResourceRequirements{},
Resources: defaultResources,
},
},
},
resources: corev1.ResourceRequirements{},
resources: nil,
expected: &corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Resources: corev1.ResourceRequirements{},
Resources: defaultResources,
},
},
},
Expand All @@ -665,7 +665,7 @@ func TestInjectResourcesIntoDeployment(t *testing.T) {
},
},
},
resources: defaultResources,
resources: &defaultResources,
expected: &corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Expand All @@ -686,7 +686,7 @@ func TestInjectResourcesIntoDeployment(t *testing.T) {
},
},
},
resources: corev1.ResourceRequirements{},
resources: &corev1.ResourceRequirements{},
expected: &corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Expand Down

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

16 changes: 8 additions & 8 deletions vendor/github.com/operator-framework/api/crds/zz_defs.go

Large diffs are not rendered by default.

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

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

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

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

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

19 changes: 10 additions & 9 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ github.com/openshift/client-go/config/informers/externalversions/config
github.com/openshift/client-go/config/informers/externalversions/config/v1
github.com/openshift/client-go/config/informers/externalversions/internalinterfaces
github.com/openshift/client-go/config/listers/config/v1
# github.com/operator-framework/api v0.5.1
# github.com/operator-framework/api v0.5.1 => github.com/joelanford/api v0.0.0-20210216180012-67617936c73e
github.com/operator-framework/api/crds
github.com/operator-framework/api/pkg/lib/version
github.com/operator-framework/api/pkg/manifests
Expand Down Expand Up @@ -811,7 +811,7 @@ helm.sh/helm/v3/pkg/storage
helm.sh/helm/v3/pkg/storage/driver
helm.sh/helm/v3/pkg/strvals
helm.sh/helm/v3/pkg/time
# k8s.io/api v0.20.0
# k8s.io/api v0.20.1
k8s.io/api/admission/v1
k8s.io/api/admission/v1beta1
k8s.io/api/admissionregistration/v1
Expand Down Expand Up @@ -858,7 +858,7 @@ k8s.io/api/scheduling/v1beta1
k8s.io/api/storage/v1
k8s.io/api/storage/v1alpha1
k8s.io/api/storage/v1beta1
# k8s.io/apiextensions-apiserver v0.20.0
# k8s.io/apiextensions-apiserver v0.20.1
k8s.io/apiextensions-apiserver/pkg/apihelpers
k8s.io/apiextensions-apiserver/pkg/apis/apiextensions
k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install
Expand All @@ -884,7 +884,7 @@ k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/apiextensio
k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/internalinterfaces
k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/v1
k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/v1beta1
# k8s.io/apimachinery v0.20.0
# k8s.io/apimachinery v0.20.1
k8s.io/apimachinery/pkg/api/equality
k8s.io/apimachinery/pkg/api/errors
k8s.io/apimachinery/pkg/api/meta
Expand Down Expand Up @@ -944,7 +944,7 @@ k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/third_party/forked/golang/json
k8s.io/apimachinery/third_party/forked/golang/netutil
k8s.io/apimachinery/third_party/forked/golang/reflect
# k8s.io/apiserver v0.20.0 => k8s.io/apiserver v0.0.0-20210107211418-525d1e3c959d
# k8s.io/apiserver v0.20.1 => k8s.io/apiserver v0.0.0-20210107211418-525d1e3c959d
k8s.io/apiserver/pkg/admission
k8s.io/apiserver/pkg/admission/configuration
k8s.io/apiserver/pkg/admission/initializer
Expand Down Expand Up @@ -1081,7 +1081,7 @@ k8s.io/cli-runtime/pkg/kustomize/k8sdeps/transformer/patch
k8s.io/cli-runtime/pkg/kustomize/k8sdeps/validator
k8s.io/cli-runtime/pkg/printers
k8s.io/cli-runtime/pkg/resource
# k8s.io/client-go v0.20.0
# k8s.io/client-go v0.20.1
k8s.io/client-go/discovery
k8s.io/client-go/discovery/cached/disk
k8s.io/client-go/discovery/cached/memory
Expand Down Expand Up @@ -1327,7 +1327,7 @@ k8s.io/client-go/util/jsonpath
k8s.io/client-go/util/keyutil
k8s.io/client-go/util/retry
k8s.io/client-go/util/workqueue
# k8s.io/code-generator v0.20.0
# k8s.io/code-generator v0.20.1
k8s.io/code-generator
k8s.io/code-generator/cmd/client-gen
k8s.io/code-generator/cmd/client-gen/args
Expand Down Expand Up @@ -1361,7 +1361,7 @@ k8s.io/code-generator/cmd/set-gen
k8s.io/code-generator/pkg/namer
k8s.io/code-generator/pkg/util
k8s.io/code-generator/third_party/forked/golang/reflect
# k8s.io/component-base v0.20.0
# k8s.io/component-base v0.20.1
k8s.io/component-base/cli/flag
k8s.io/component-base/config
k8s.io/component-base/config/v1alpha1
Expand Down Expand Up @@ -1446,7 +1446,7 @@ k8s.io/utils/trace
# sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14
sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client
sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client
# sigs.k8s.io/controller-runtime v0.7.0
# sigs.k8s.io/controller-runtime v0.8.0
sigs.k8s.io/controller-runtime
sigs.k8s.io/controller-runtime/pkg/builder
sigs.k8s.io/controller-runtime/pkg/cache
Expand All @@ -1455,6 +1455,7 @@ sigs.k8s.io/controller-runtime/pkg/client
sigs.k8s.io/controller-runtime/pkg/client/apiutil
sigs.k8s.io/controller-runtime/pkg/client/config
sigs.k8s.io/controller-runtime/pkg/client/fake
sigs.k8s.io/controller-runtime/pkg/cluster
sigs.k8s.io/controller-runtime/pkg/config
sigs.k8s.io/controller-runtime/pkg/config/v1alpha1
sigs.k8s.io/controller-runtime/pkg/controller
Expand Down
13 changes: 6 additions & 7 deletions vendor/sigs.k8s.io/controller-runtime/go.mod

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

Loading

0 comments on commit 87f78f7

Please sign in to comment.