From 10246d5e86d0a1b6d60b804fb10367b1729a98ee Mon Sep 17 00:00:00 2001 From: dmitriy kalinin Date: Wed, 25 Jul 2018 15:29:27 -0700 Subject: [PATCH] deep copy domain.Config object before returning it Fixes #1680 --- hack/update-codegen.sh | 2 +- pkg/controller/route/config/doc.go | 2 + .../route/config/zz_generated.deepcopy.go | 72 +++++++++++++++++++ pkg/controller/route/route.go | 2 +- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 pkg/controller/route/config/zz_generated.deepcopy.go diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 3ef96e6b44e7..7cd072a57b51 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -32,7 +32,7 @@ ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ # Depends on generate-groups.sh to install bin/deepcopy-gen ${GOPATH}/bin/deepcopy-gen --input-dirs \ - github.com/knative/serving/pkg/controller/revision/config,github.com/knative/serving/pkg/autoscaler,github.com/knative/serving/pkg/logging \ + github.com/knative/serving/pkg/controller/revision/config,github.com/knative/serving/pkg/controller/route/config,github.com/knative/serving/pkg/autoscaler,github.com/knative/serving/pkg/logging \ -O zz_generated.deepcopy \ --go-header-file ${SERVING_ROOT}/hack/boilerplate/boilerplate.go.txt diff --git a/pkg/controller/route/config/doc.go b/pkg/controller/route/config/doc.go index b35a1e8aaaeb..25512a648445 100644 --- a/pkg/controller/route/config/doc.go +++ b/pkg/controller/route/config/doc.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// +k8s:deepcopy-gen=package + // Package config holds the typed objects that define the schemas for // assorted ConfigMap objects on which the Route controller depends. package config diff --git a/pkg/controller/route/config/zz_generated.deepcopy.go b/pkg/controller/route/config/zz_generated.deepcopy.go new file mode 100644 index 000000000000..647fd701d707 --- /dev/null +++ b/pkg/controller/route/config/zz_generated.deepcopy.go @@ -0,0 +1,72 @@ +// +build !ignore_autogenerated + +/* +Copyright 2018 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. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package config + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Domain) DeepCopyInto(out *Domain) { + *out = *in + if in.Domains != nil { + in, out := &in.Domains, &out.Domains + *out = make(map[string]*LabelSelector, len(*in)) + for key, val := range *in { + if val == nil { + (*out)[key] = nil + } else { + (*out)[key] = new(LabelSelector) + val.DeepCopyInto((*out)[key]) + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Domain. +func (in *Domain) DeepCopy() *Domain { + if in == nil { + return nil + } + out := new(Domain) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LabelSelector) DeepCopyInto(out *LabelSelector) { + *out = *in + if in.Selector != nil { + in, out := &in.Selector, &out.Selector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LabelSelector. +func (in *LabelSelector) DeepCopy() *LabelSelector { + if in == nil { + return nil + } + out := new(LabelSelector) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/controller/route/route.go b/pkg/controller/route/route.go index 53e92e2f67cb..e25c98aa53ef 100644 --- a/pkg/controller/route/route.go +++ b/pkg/controller/route/route.go @@ -259,7 +259,7 @@ func loggerWithRouteInfo(logger *zap.SugaredLogger, ns string, name string) *zap func (c *Controller) getDomainConfig() *config.Domain { c.domainConfigMutex.Lock() defer c.domainConfigMutex.Unlock() - return c.domainConfig + return c.domainConfig.DeepCopy() } func (c *Controller) routeDomain(route *v1alpha1.Route) string {