diff --git a/go.mod b/go.mod index 18118f42e3e..0fed09b9696 100644 --- a/go.mod +++ b/go.mod @@ -125,7 +125,7 @@ require ( k8s.io/controller-manager v0.0.0 k8s.io/cri-api v0.0.0 k8s.io/csi-translation-lib v0.0.0 - k8s.io/gengo v0.0.0-20201113003025-83324d819ded + k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 k8s.io/heapster v1.2.0-beta.1 k8s.io/klog/v2 v2.4.0 k8s.io/kube-aggregator v0.0.0 @@ -505,7 +505,7 @@ replace ( k8s.io/controller-manager => ./staging/src/k8s.io/controller-manager k8s.io/cri-api => ./staging/src/k8s.io/cri-api k8s.io/csi-translation-lib => ./staging/src/k8s.io/csi-translation-lib - k8s.io/gengo => k8s.io/gengo v0.0.0-20201113003025-83324d819ded + k8s.io/gengo => k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 k8s.io/heapster => k8s.io/heapster v1.2.0-beta.1 k8s.io/klog/v2 => k8s.io/klog/v2 v2.4.0 k8s.io/kube-aggregator => ./staging/src/k8s.io/kube-aggregator diff --git a/go.sum b/go.sum index 32588af3339..e60ba04ee36 100644 --- a/go.sum +++ b/go.sum @@ -589,8 +589,8 @@ gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81 gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/heapster v1.2.0-beta.1 h1:lUsE/AHOMHpi3MLlBEkaU8Esxm5QhdyCrv1o7ot0s84= k8s.io/heapster v1.2.0-beta.1/go.mod h1:h1uhptVXMwC8xtZBYsPXKVi8fpdlYkTs6k949KozGrM= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/pkg/apis/apps/v1/zz_generated.defaults.go b/pkg/apis/apps/v1/zz_generated.defaults.go index 58a99f3f6b6..80dba3b7946 100644 --- a/pkg/apis/apps/v1/zz_generated.defaults.go +++ b/pkg/apis/apps/v1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1 import ( - "reflect" - v1 "k8s.io/api/apps/v1" runtime "k8s.io/apimachinery/pkg/runtime" corev1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -109,7 +107,7 @@ func SetObjectDefaults_DaemonSet(in *v1.DaemonSet) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -159,7 +157,7 @@ func SetObjectDefaults_DaemonSet(in *v1.DaemonSet) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -209,7 +207,7 @@ func SetObjectDefaults_DaemonSet(in *v1.DaemonSet) { corev1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -330,7 +328,7 @@ func SetObjectDefaults_Deployment(in *v1.Deployment) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -380,7 +378,7 @@ func SetObjectDefaults_Deployment(in *v1.Deployment) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -430,7 +428,7 @@ func SetObjectDefaults_Deployment(in *v1.Deployment) { corev1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -551,7 +549,7 @@ func SetObjectDefaults_ReplicaSet(in *v1.ReplicaSet) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -601,7 +599,7 @@ func SetObjectDefaults_ReplicaSet(in *v1.ReplicaSet) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -651,7 +649,7 @@ func SetObjectDefaults_ReplicaSet(in *v1.ReplicaSet) { corev1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -772,7 +770,7 @@ func SetObjectDefaults_StatefulSet(in *v1.StatefulSet) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -822,7 +820,7 @@ func SetObjectDefaults_StatefulSet(in *v1.StatefulSet) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -872,7 +870,7 @@ func SetObjectDefaults_StatefulSet(in *v1.StatefulSet) { corev1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/apps/v1beta1/zz_generated.defaults.go b/pkg/apis/apps/v1beta1/zz_generated.defaults.go index f248064ce3e..01e84f4e4f8 100644 --- a/pkg/apis/apps/v1beta1/zz_generated.defaults.go +++ b/pkg/apis/apps/v1beta1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1beta1 import ( - "reflect" - v1beta1 "k8s.io/api/apps/v1beta1" runtime "k8s.io/apimachinery/pkg/runtime" v1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -105,7 +103,7 @@ func SetObjectDefaults_Deployment(in *v1beta1.Deployment) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -155,7 +153,7 @@ func SetObjectDefaults_Deployment(in *v1beta1.Deployment) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -205,7 +203,7 @@ func SetObjectDefaults_Deployment(in *v1beta1.Deployment) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -326,7 +324,7 @@ func SetObjectDefaults_StatefulSet(in *v1beta1.StatefulSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -376,7 +374,7 @@ func SetObjectDefaults_StatefulSet(in *v1beta1.StatefulSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -426,7 +424,7 @@ func SetObjectDefaults_StatefulSet(in *v1beta1.StatefulSet) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/apps/v1beta2/zz_generated.defaults.go b/pkg/apis/apps/v1beta2/zz_generated.defaults.go index ffabe5f60e7..76d66940c79 100644 --- a/pkg/apis/apps/v1beta2/zz_generated.defaults.go +++ b/pkg/apis/apps/v1beta2/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1beta2 import ( - "reflect" - v1beta2 "k8s.io/api/apps/v1beta2" runtime "k8s.io/apimachinery/pkg/runtime" v1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -109,7 +107,7 @@ func SetObjectDefaults_DaemonSet(in *v1beta2.DaemonSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -159,7 +157,7 @@ func SetObjectDefaults_DaemonSet(in *v1beta2.DaemonSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -209,7 +207,7 @@ func SetObjectDefaults_DaemonSet(in *v1beta2.DaemonSet) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -330,7 +328,7 @@ func SetObjectDefaults_Deployment(in *v1beta2.Deployment) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -380,7 +378,7 @@ func SetObjectDefaults_Deployment(in *v1beta2.Deployment) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -430,7 +428,7 @@ func SetObjectDefaults_Deployment(in *v1beta2.Deployment) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -551,7 +549,7 @@ func SetObjectDefaults_ReplicaSet(in *v1beta2.ReplicaSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -601,7 +599,7 @@ func SetObjectDefaults_ReplicaSet(in *v1beta2.ReplicaSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -651,7 +649,7 @@ func SetObjectDefaults_ReplicaSet(in *v1beta2.ReplicaSet) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -772,7 +770,7 @@ func SetObjectDefaults_StatefulSet(in *v1beta2.StatefulSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -822,7 +820,7 @@ func SetObjectDefaults_StatefulSet(in *v1beta2.StatefulSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -872,7 +870,7 @@ func SetObjectDefaults_StatefulSet(in *v1beta2.StatefulSet) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/batch/v1/zz_generated.defaults.go b/pkg/apis/batch/v1/zz_generated.defaults.go index ffeba646f2a..969ea16f223 100644 --- a/pkg/apis/batch/v1/zz_generated.defaults.go +++ b/pkg/apis/batch/v1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1 import ( - "reflect" - v1 "k8s.io/api/batch/v1" runtime "k8s.io/apimachinery/pkg/runtime" corev1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -103,7 +101,7 @@ func SetObjectDefaults_Job(in *v1.Job) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -153,7 +151,7 @@ func SetObjectDefaults_Job(in *v1.Job) { corev1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -203,7 +201,7 @@ func SetObjectDefaults_Job(in *v1.Job) { corev1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/batch/v1beta1/zz_generated.defaults.go b/pkg/apis/batch/v1beta1/zz_generated.defaults.go index 2b11eb14698..94f57743cd1 100644 --- a/pkg/apis/batch/v1beta1/zz_generated.defaults.go +++ b/pkg/apis/batch/v1beta1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1beta1 import ( - "reflect" - v1beta1 "k8s.io/api/batch/v1beta1" runtime "k8s.io/apimachinery/pkg/runtime" v1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -104,7 +102,7 @@ func SetObjectDefaults_CronJob(in *v1beta1.CronJob) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -154,7 +152,7 @@ func SetObjectDefaults_CronJob(in *v1beta1.CronJob) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -204,7 +202,7 @@ func SetObjectDefaults_CronJob(in *v1beta1.CronJob) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -324,7 +322,7 @@ func SetObjectDefaults_JobTemplate(in *v1beta1.JobTemplate) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -374,7 +372,7 @@ func SetObjectDefaults_JobTemplate(in *v1beta1.JobTemplate) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -424,7 +422,7 @@ func SetObjectDefaults_JobTemplate(in *v1beta1.JobTemplate) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/batch/v2alpha1/zz_generated.defaults.go b/pkg/apis/batch/v2alpha1/zz_generated.defaults.go index eb96b04cb57..3c43daae355 100644 --- a/pkg/apis/batch/v2alpha1/zz_generated.defaults.go +++ b/pkg/apis/batch/v2alpha1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v2alpha1 import ( - "reflect" - v2alpha1 "k8s.io/api/batch/v2alpha1" runtime "k8s.io/apimachinery/pkg/runtime" v1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -104,7 +102,7 @@ func SetObjectDefaults_CronJob(in *v2alpha1.CronJob) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -154,7 +152,7 @@ func SetObjectDefaults_CronJob(in *v2alpha1.CronJob) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -204,7 +202,7 @@ func SetObjectDefaults_CronJob(in *v2alpha1.CronJob) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -324,7 +322,7 @@ func SetObjectDefaults_JobTemplate(in *v2alpha1.JobTemplate) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -374,7 +372,7 @@ func SetObjectDefaults_JobTemplate(in *v2alpha1.JobTemplate) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -424,7 +422,7 @@ func SetObjectDefaults_JobTemplate(in *v2alpha1.JobTemplate) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/core/v1/zz_generated.defaults.go b/pkg/apis/core/v1/zz_generated.defaults.go index 89f45a026b6..2863cc3ab8f 100644 --- a/pkg/apis/core/v1/zz_generated.defaults.go +++ b/pkg/apis/core/v1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1 import ( - "reflect" - v1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -93,7 +91,7 @@ func SetObjectDefaults_EphemeralContainers(in *v1.EphemeralContainers) { SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -291,7 +289,7 @@ func SetObjectDefaults_Pod(in *v1.Pod) { SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -341,7 +339,7 @@ func SetObjectDefaults_Pod(in *v1.Pod) { SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -391,7 +389,7 @@ func SetObjectDefaults_Pod(in *v1.Pod) { SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -511,7 +509,7 @@ func SetObjectDefaults_PodTemplate(in *v1.PodTemplate) { SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -561,7 +559,7 @@ func SetObjectDefaults_PodTemplate(in *v1.PodTemplate) { SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -611,7 +609,7 @@ func SetObjectDefaults_PodTemplate(in *v1.PodTemplate) { SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -733,7 +731,7 @@ func SetObjectDefaults_ReplicationController(in *v1.ReplicationController) { SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -783,7 +781,7 @@ func SetObjectDefaults_ReplicationController(in *v1.ReplicationController) { SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -833,7 +831,7 @@ func SetObjectDefaults_ReplicationController(in *v1.ReplicationController) { SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/pkg/apis/extensions/v1beta1/zz_generated.defaults.go b/pkg/apis/extensions/v1beta1/zz_generated.defaults.go index 317003e1dbe..2d28b577976 100644 --- a/pkg/apis/extensions/v1beta1/zz_generated.defaults.go +++ b/pkg/apis/extensions/v1beta1/zz_generated.defaults.go @@ -21,8 +21,6 @@ limitations under the License. package v1beta1 import ( - "reflect" - v1beta1 "k8s.io/api/extensions/v1beta1" runtime "k8s.io/apimachinery/pkg/runtime" v1 "k8s.io/kubernetes/pkg/apis/core/v1" @@ -113,7 +111,7 @@ func SetObjectDefaults_DaemonSet(in *v1beta1.DaemonSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -163,7 +161,7 @@ func SetObjectDefaults_DaemonSet(in *v1beta1.DaemonSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -213,7 +211,7 @@ func SetObjectDefaults_DaemonSet(in *v1beta1.DaemonSet) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -334,7 +332,7 @@ func SetObjectDefaults_Deployment(in *v1beta1.Deployment) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -384,7 +382,7 @@ func SetObjectDefaults_Deployment(in *v1beta1.Deployment) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -434,7 +432,7 @@ func SetObjectDefaults_Deployment(in *v1beta1.Deployment) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -596,7 +594,7 @@ func SetObjectDefaults_ReplicaSet(in *v1beta1.ReplicaSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -646,7 +644,7 @@ func SetObjectDefaults_ReplicaSet(in *v1beta1.ReplicaSet) { v1.SetDefaults_Container(a) for j := range a.Ports { b := &a.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } @@ -696,7 +694,7 @@ func SetObjectDefaults_ReplicaSet(in *v1beta1.ReplicaSet) { v1.SetDefaults_EphemeralContainer(a) for j := range a.EphemeralContainerCommon.Ports { b := &a.EphemeralContainerCommon.Ports[j] - if reflect.ValueOf(b.Protocol).IsZero() { + if b.Protocol == "" { b.Protocol = "TCP" } } diff --git a/staging/src/k8s.io/apiextensions-apiserver/go.sum b/staging/src/k8s.io/apiextensions-apiserver/go.sum index 5e20c4eaea6..69ea8707046 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/go.sum +++ b/staging/src/k8s.io/apiextensions-apiserver/go.sum @@ -677,8 +677,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/staging/src/k8s.io/code-generator/go.mod b/staging/src/k8s.io/code-generator/go.mod index 404d8f3c26b..52aa67052e8 100644 --- a/staging/src/k8s.io/code-generator/go.mod +++ b/staging/src/k8s.io/code-generator/go.mod @@ -17,7 +17,7 @@ require ( golang.org/x/text v0.3.4 // indirect golang.org/x/tools v0.0.0-20200616133436-c1934b75d054 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - k8s.io/gengo v0.0.0-20201113003025-83324d819ded + k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 k8s.io/klog/v2 v2.4.0 k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd ) diff --git a/staging/src/k8s.io/code-generator/go.sum b/staging/src/k8s.io/code-generator/go.sum index af35786dcd7..638fb5c9300 100644 --- a/staging/src/k8s.io/code-generator/go.sum +++ b/staging/src/k8s.io/code-generator/go.sum @@ -131,8 +131,8 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/staging/src/k8s.io/kube-aggregator/go.sum b/staging/src/k8s.io/kube-aggregator/go.sum index 8aa1ffdbab9..3d5634e27b3 100644 --- a/staging/src/k8s.io/kube-aggregator/go.sum +++ b/staging/src/k8s.io/kube-aggregator/go.sum @@ -677,8 +677,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/staging/src/k8s.io/kubectl/go.sum b/staging/src/k8s.io/kubectl/go.sum index 0e2bee7a756..65671195da3 100644 --- a/staging/src/k8s.io/kubectl/go.sum +++ b/staging/src/k8s.io/kubectl/go.sum @@ -635,7 +635,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/staging/src/k8s.io/metrics/go.sum b/staging/src/k8s.io/metrics/go.sum index daea75c36c8..15f35a6912c 100644 --- a/staging/src/k8s.io/metrics/go.sum +++ b/staging/src/k8s.io/metrics/go.sum @@ -427,8 +427,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/staging/src/k8s.io/sample-apiserver/go.sum b/staging/src/k8s.io/sample-apiserver/go.sum index b7273ee9772..68f359a628b 100644 --- a/staging/src/k8s.io/sample-apiserver/go.sum +++ b/staging/src/k8s.io/sample-apiserver/go.sum @@ -674,8 +674,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/staging/src/k8s.io/sample-controller/go.sum b/staging/src/k8s.io/sample-controller/go.sum index b152b9c8d7c..29438c5ecaf 100644 --- a/staging/src/k8s.io/sample-controller/go.sum +++ b/staging/src/k8s.io/sample-controller/go.sum @@ -433,8 +433,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded h1:JApXBKYyB7l9xx+DK7/+mFjC7A9Bt5A93FPvFD0HIFE= -k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw= +k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= diff --git a/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go b/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go index cdb6f7c7e43..72782b166e5 100644 --- a/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go +++ b/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go @@ -23,6 +23,7 @@ import ( "io" "path/filepath" "reflect" + "strconv" "strings" "k8s.io/gengo/args" @@ -50,7 +51,7 @@ var typeZeroValue = map[string]interface{}{ "int16": 0., "int32": 0., "int64": 0., - "byte": 0, + "byte": 0., "float64": 0., "float32": 0., "bool": false, @@ -839,6 +840,12 @@ type callNode struct { // For example 1 corresponds to setting a default value and taking its pointer while // 2 corresponds to setting a default value and taking its pointer's pointer // 0 implies that no pointers are used + // This is used in situations where a field is a pointer to a primitive value rather than a primitive value itself. + // + // type A { + // +default="foo" + // Field *string + // } defaultDepth int // defaultType is the type of the default value. @@ -899,80 +906,90 @@ func (n *callNode) writeCalls(varName string, isVarPointer bool, sw *generator.S } } +func getTypeZeroValue(t string) (interface{}, error) { + defaultZero, ok := typeZeroValue[t] + if !ok { + return nil, fmt.Errorf("Cannot find zero value for type %v in typeZeroValue", t) + } + + // To generate the code for empty string, they must be quoted + if defaultZero == "" { + defaultZero = strconv.Quote(defaultZero.(string)) + } + return defaultZero, nil +} + func (n *callNode) writeDefaulter(varName string, index string, isVarPointer bool, sw *generator.SnippetWriter) { if n.defaultValue == "" { return } - varPointer := varName - if !isVarPointer { - varPointer = "&" + varPointer - } - args := generator.Args{ "defaultValue": n.defaultValue, - "varPointer": varPointer, "varName": varName, "index": index, "varDepth": n.defaultDepth, "varType": n.defaultType, } - if n.index { - sw.Do("if reflect.ValueOf($.var$[$.index$]).IsZero() {\n", generator.Args{"var": varName, "index": index}) - if n.defaultIsPrimitive { - if n.defaultDepth > 0 { - sw.Do("var ptrVar$.varDepth$ $.varType$ = $.defaultValue$\n", args) - for i := n.defaultDepth; i > 0; i-- { - sw.Do("ptrVar$.ptri$ := &ptrVar$.i$\n", generator.Args{"i": fmt.Sprintf("%d", i), "ptri": fmt.Sprintf("%d", (i - 1))}) - } - sw.Do("$.varName$[$.index$] = ptrVar0", args) - } else { - sw.Do("$.varName$[$.index$] = $.defaultValue$", args) - } - } else { - sw.Do("if err := json.Unmarshal([]byte(`$.defaultValue$`), $.varPointer$[$.index$]); err != nil {\n", args) - sw.Do("panic(err)\n", nil) - sw.Do("}\n", nil) - } - } else if n.key { - mapDefaultVar := index + "_default" - args["mapDefaultVar"] = mapDefaultVar - sw.Do("if reflect.ValueOf($.var$[$.index$]).IsZero() {\n", generator.Args{"var": varName, "index": index}) + variablePlaceholder := "" - if n.defaultIsPrimitive { - if n.defaultDepth > 0 { - sw.Do("var ptrVar$.varDepth$ $.varType$ = $.defaultValue$\n", args) - for i := n.defaultDepth; i > 0; i-- { - sw.Do("ptrVar$.ptri$ := &ptrVar$.i$\n", generator.Args{"i": fmt.Sprintf("%d", i), "ptri": fmt.Sprintf("%d", (i - 1))}) - } - sw.Do("$.varName$[$.index$] = ptrVar0", args) - } else { - sw.Do("$.varName$[$.index$] = $.defaultValue$", args) + if n.index { + // Defaulting for array + variablePlaceholder = "$.varName$[$.index$]" + } else if n.key { + // Defaulting for map + variablePlaceholder = "$.varName$[$.index$]" + mapDefaultVar := args["index"].(string) + "_default" + args["mapDefaultVar"] = mapDefaultVar + } else { + // Defaulting for primitive type + variablePlaceholder = "$.varName$" + } + + // defaultIsPrimitive is true if the type or underlying type (in an array/map) is primitive + // or is a pointer to a primitive type + // (Eg: int, map[string]*string, []int) + if n.defaultIsPrimitive { + // If the default value is a primitive when the assigned type is a pointer + // keep using the address-of operator on the primitive value until the types match + if n.defaultDepth > 0 { + sw.Do(fmt.Sprintf("if %s == nil {\n", variablePlaceholder), args) + sw.Do("var ptrVar$.varDepth$ $.varType$ = $.defaultValue$\n", args) + // We iterate until a depth of 1 instead of 0 because the following line + // `if $.varName$ == &ptrVar1` accounts for 1 level already + for i := n.defaultDepth; i > 1; i-- { + sw.Do("ptrVar$.ptri$ := &ptrVar$.i$\n", generator.Args{"i": fmt.Sprintf("%d", i), "ptri": fmt.Sprintf("%d", (i - 1))}) } + sw.Do(fmt.Sprintf("%s = &ptrVar1", variablePlaceholder), args) } else { - sw.Do("$.mapDefaultVar$ := $.varName$[$.index$]\n", args) - sw.Do("if err := json.Unmarshal([]byte(`$.defaultValue$`), &$.mapDefaultVar$); err != nil {\n", args) - sw.Do("panic(err)\n", nil) - sw.Do("}\n", nil) - sw.Do("$.varName$[$.index$] = $.mapDefaultVar$\n", args) + // For primitive types, nil checks cannot be used and the zero value must be determined + defaultZero, err := getTypeZeroValue(n.defaultType) + if err != nil { + klog.Error(err) + } + args["defaultZero"] = defaultZero + + sw.Do(fmt.Sprintf("if %s == $.defaultZero$ {\n", variablePlaceholder), args) + sw.Do(fmt.Sprintf("%s = $.defaultValue$", variablePlaceholder), args) } } else { - sw.Do("if reflect.ValueOf($.var$).IsZero() {\n", generator.Args{"var": varName}) - - if n.defaultIsPrimitive { - if n.defaultDepth > 0 { - sw.Do("var ptrVar$.varDepth$ $.varType$ = $.defaultValue$\n", args) - for i := n.defaultDepth; i > 0; i-- { - sw.Do("ptrVar$.ptri$ := &ptrVar$.i$\n", generator.Args{"i": fmt.Sprintf("%d", i), "ptri": fmt.Sprintf("%d", (i - 1))}) - } - sw.Do("$.varName$ = ptrVar0", args) - } else { - sw.Do("$.varName$ = $.defaultValue$", args) - } + sw.Do(fmt.Sprintf("if %s == nil {\n", variablePlaceholder), args) + // Map values are not directly addressable and we need a temporary variable to do json unmarshalling + // This applies to maps with non-primitive values (eg: map[string]SubStruct) + if n.key { + sw.Do("$.mapDefaultVar$ := $.varName$[$.index$]\n", args) + sw.Do("if err := json.Unmarshal([]byte(`$.defaultValue$`), &$.mapDefaultVar$); err != nil {\n", args) } else { - sw.Do("if err := json.Unmarshal([]byte(`$.defaultValue$`), $.varPointer$); err != nil {\n", args) - sw.Do("panic(err)\n", nil) - sw.Do("}\n", nil) + variablePointer := variablePlaceholder + if !isVarPointer { + variablePointer = "&" + variablePointer + } + sw.Do(fmt.Sprintf("if err := json.Unmarshal([]byte(`$.defaultValue$`), %s); err != nil {\n", variablePointer), args) + } + sw.Do("panic(err)\n", nil) + sw.Do("}\n", nil) + if n.key { + sw.Do("$.varName$[$.index$] = $.mapDefaultVar$\n", args) } } sw.Do("}\n", nil) diff --git a/vendor/k8s.io/gengo/parser/parse.go b/vendor/k8s.io/gengo/parser/parse.go index 14b5ae13479..635afcf282d 100644 --- a/vendor/k8s.io/gengo/parser/parse.go +++ b/vendor/k8s.io/gengo/parser/parse.go @@ -493,6 +493,19 @@ func (b *Builder) FindTypes() (types.Universe, error) { return u, nil } +// addCommentsToType takes any accumulated comment lines prior to obj and +// attaches them to the type t. +func (b *Builder) addCommentsToType(obj tc.Object, t *types.Type) { + c1 := b.priorCommentLines(obj.Pos(), 1) + // c1.Text() is safe if c1 is nil + t.CommentLines = splitLines(c1.Text()) + if c1 == nil { + t.SecondClosestCommentLines = splitLines(b.priorCommentLines(obj.Pos(), 2).Text()) + } else { + t.SecondClosestCommentLines = splitLines(b.priorCommentLines(c1.List[0].Slash, 2).Text()) + } +} + // findTypesIn finalizes the package import and searches through the package // for types. func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error { @@ -536,35 +549,23 @@ func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error tn, ok := obj.(*tc.TypeName) if ok { t := b.walkType(*u, nil, tn.Type()) - c1 := b.priorCommentLines(obj.Pos(), 1) - // c1.Text() is safe if c1 is nil - t.CommentLines = splitLines(c1.Text()) - if c1 == nil { - t.SecondClosestCommentLines = splitLines(b.priorCommentLines(obj.Pos(), 2).Text()) - } else { - t.SecondClosestCommentLines = splitLines(b.priorCommentLines(c1.List[0].Slash, 2).Text()) - } + b.addCommentsToType(obj, t) } tf, ok := obj.(*tc.Func) // We only care about functions, not concrete/abstract methods. if ok && tf.Type() != nil && tf.Type().(*tc.Signature).Recv() == nil { t := b.addFunction(*u, nil, tf) - c1 := b.priorCommentLines(obj.Pos(), 1) - // c1.Text() is safe if c1 is nil - t.CommentLines = splitLines(c1.Text()) - if c1 == nil { - t.SecondClosestCommentLines = splitLines(b.priorCommentLines(obj.Pos(), 2).Text()) - } else { - t.SecondClosestCommentLines = splitLines(b.priorCommentLines(c1.List[0].Slash, 2).Text()) - } + b.addCommentsToType(obj, t) } tv, ok := obj.(*tc.Var) if ok && !tv.IsField() { - b.addVariable(*u, nil, tv) + t := b.addVariable(*u, nil, tv) + b.addCommentsToType(obj, t) } tconst, ok := obj.(*tc.Const) if ok { - b.addConstant(*u, nil, tconst) + t := b.addConstant(*u, nil, tconst) + b.addCommentsToType(obj, t) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index d789fe16f0d..fdb00e50393 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2271,9 +2271,9 @@ k8s.io/cri-api/pkg/apis/testing k8s.io/csi-translation-lib # k8s.io/csi-translation-lib => ./staging/src/k8s.io/csi-translation-lib k8s.io/csi-translation-lib/plugins -# k8s.io/gengo v0.0.0-20201113003025-83324d819ded => k8s.io/gengo v0.0.0-20201113003025-83324d819ded +# k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 => k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 ## explicit -# k8s.io/gengo => k8s.io/gengo v0.0.0-20201113003025-83324d819ded +# k8s.io/gengo => k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 k8s.io/gengo/args k8s.io/gengo/examples/deepcopy-gen/generators k8s.io/gengo/examples/defaulter-gen/generators