Merge pull request #116166 from pohly/test-go-vet
fix "go vet" issues, check as part of golangci-lint Kubernetes-commit: ff735dff85367c2a096c4065b8b3c1fbbeecabc4
This commit is contained in:
commit
1cdc9eb33b
16
go.mod
16
go.mod
|
@ -43,11 +43,11 @@ require (
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0
|
gopkg.in/square/go-jose.v2 v2.6.0
|
||||||
k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab
|
k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab
|
||||||
k8s.io/apimachinery v0.0.0-20230303235433-5b1cff80ea06
|
k8s.io/apimachinery v0.0.0-20230303235435-f357b1fa74b7
|
||||||
k8s.io/client-go v0.0.0-20230304000202-d39f8291fc57
|
k8s.io/client-go v0.0.0-20230304000204-06ad6b391d35
|
||||||
k8s.io/component-base v0.0.0-20230304000858-ddedd087ad1e
|
k8s.io/component-base v0.0.0-20230304000900-3bf8af940f29
|
||||||
k8s.io/klog/v2 v2.90.1
|
k8s.io/klog/v2 v2.90.1
|
||||||
k8s.io/kms v0.0.0-20230303123242-0b3f9dde5fcd
|
k8s.io/kms v0.0.0-20230304001132-5439f76ca4a7
|
||||||
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d
|
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d
|
||||||
k8s.io/utils v0.0.0-20230209194617-a36077c30491
|
k8s.io/utils v0.0.0-20230209194617-a36077c30491
|
||||||
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.1
|
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.1
|
||||||
|
@ -125,8 +125,8 @@ require (
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
k8s.io/api => k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab
|
k8s.io/api => k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab
|
||||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230303235433-5b1cff80ea06
|
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230303235435-f357b1fa74b7
|
||||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20230304000202-d39f8291fc57
|
k8s.io/client-go => k8s.io/client-go v0.0.0-20230304000204-06ad6b391d35
|
||||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20230304000858-ddedd087ad1e
|
k8s.io/component-base => k8s.io/component-base v0.0.0-20230304000900-3bf8af940f29
|
||||||
k8s.io/kms => k8s.io/kms v0.0.0-20230303123242-0b3f9dde5fcd
|
k8s.io/kms => k8s.io/kms v0.0.0-20230304001132-5439f76ca4a7
|
||||||
)
|
)
|
||||||
|
|
16
go.sum
16
go.sum
|
@ -876,16 +876,16 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
|
||||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab h1:peGI8OxM+LOJxG8FqX/y6BVELxehZ4fDq9cm1a5Qaz0=
|
k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab h1:peGI8OxM+LOJxG8FqX/y6BVELxehZ4fDq9cm1a5Qaz0=
|
||||||
k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab/go.mod h1:ihVCDKSD6f+H/yGKVpY9HSgpw4StgSvrI3dbK05M9a8=
|
k8s.io/api v0.0.0-20230303235756-fc1b77c3f4ab/go.mod h1:ihVCDKSD6f+H/yGKVpY9HSgpw4StgSvrI3dbK05M9a8=
|
||||||
k8s.io/apimachinery v0.0.0-20230303235433-5b1cff80ea06 h1:d8NkMUaqPq1ghtNIScF2RIPgGhSu+scUUrxsinWDThg=
|
k8s.io/apimachinery v0.0.0-20230303235435-f357b1fa74b7 h1:YN43Lvs3Pj9iQmuWGojeBiFdz1mkrxe0EZn7Ba3TMpQ=
|
||||||
k8s.io/apimachinery v0.0.0-20230303235433-5b1cff80ea06/go.mod h1:jlJwObMa4oKAEOMnAeEaqeiM+Fwd/CbAwNyQ7OaEwS0=
|
k8s.io/apimachinery v0.0.0-20230303235435-f357b1fa74b7/go.mod h1:jlJwObMa4oKAEOMnAeEaqeiM+Fwd/CbAwNyQ7OaEwS0=
|
||||||
k8s.io/client-go v0.0.0-20230304000202-d39f8291fc57 h1:1poxm/0OkMXI+YWheufVMRgXiYBW3Kq2PM+/sHDqvvg=
|
k8s.io/client-go v0.0.0-20230304000204-06ad6b391d35 h1:9uwNzISbibeQwpbp/a9OFj2Zk98INi4pJfByXGK5nGQ=
|
||||||
k8s.io/client-go v0.0.0-20230304000202-d39f8291fc57/go.mod h1:j1Eg/I6nZcgoThl8TATyMIg+1xoKMW0D3JnR2VnBm6c=
|
k8s.io/client-go v0.0.0-20230304000204-06ad6b391d35/go.mod h1:D9bGnWQ1292GhAR0f2uumanvVdOHddJlD+7OlyUorYM=
|
||||||
k8s.io/component-base v0.0.0-20230304000858-ddedd087ad1e h1:PuygjVw/jQzOBSJ1s6xv1oA7Dc5ZvEDxfpS/5k8ZMHQ=
|
k8s.io/component-base v0.0.0-20230304000900-3bf8af940f29 h1:26PuXs5/GsCX5EPltZN9KjZqkW/EwYHaebfNmIK3Wxc=
|
||||||
k8s.io/component-base v0.0.0-20230304000858-ddedd087ad1e/go.mod h1:vldhe13R/1pbgyrY1SwSHHwol4MWZNyU0J5mCvBECfA=
|
k8s.io/component-base v0.0.0-20230304000900-3bf8af940f29/go.mod h1:1aFiUfjXiy45a88xJmd/nSkReVCoyShEHbGmWJQbp2Q=
|
||||||
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
|
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
|
||||||
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||||
k8s.io/kms v0.0.0-20230303123242-0b3f9dde5fcd h1:0vh05+hg06/s6B0rPgOZ4ej5AH7GNp4qX6GLEa+pjVw=
|
k8s.io/kms v0.0.0-20230304001132-5439f76ca4a7 h1:futlV+711Mpxr0irzwwlAYRWMkjJhuCegLVTdMdVSSo=
|
||||||
k8s.io/kms v0.0.0-20230303123242-0b3f9dde5fcd/go.mod h1:BsJEqK1MWN8sYXv2fVg9sQ8DJcmCIGFo/WDDOokPOTQ=
|
k8s.io/kms v0.0.0-20230304001132-5439f76ca4a7/go.mod h1:ezC/xRef8j8anJmrcqdtAo4QRfpJWXlKyJlkkua+lwg=
|
||||||
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d h1:VcFq5n7wCJB2FQMCIHfC+f+jNcGgNMar1uKd6rVlifU=
|
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d h1:VcFq5n7wCJB2FQMCIHfC+f+jNcGgNMar1uKd6rVlifU=
|
||||||
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY=
|
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY=
|
||||||
k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY=
|
k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY=
|
||||||
|
|
|
@ -53,6 +53,14 @@ func (fc *fakeCriteria) GetParsedObjectSelector() (labels.Selector, error) {
|
||||||
return metav1.LabelSelectorAsSelector(fc.matchResources.ObjectSelector)
|
return metav1.LabelSelectorAsSelector(fc.matchResources.ObjectSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gvr(group, version, resource string) schema.GroupVersionResource {
|
||||||
|
return schema.GroupVersionResource{Group: group, Version: version, Resource: resource}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gvk(group, version, kind string) schema.GroupVersionKind {
|
||||||
|
return schema.GroupVersionKind{Group: group, Version: version, Kind: kind}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMatcher(t *testing.T) {
|
func TestMatcher(t *testing.T) {
|
||||||
a := &Matcher{namespaceMatcher: &namespace.Matcher{}, objectMatcher: &object.Matcher{}}
|
a := &Matcher{namespaceMatcher: &namespace.Matcher{}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
@ -67,19 +75,19 @@ func TestMatcher(t *testing.T) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
// register invalid kinds to trigger an error
|
// register invalid kinds to trigger an error
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"example.com", "v1", "widgets"}, "", schema.GroupVersionKind{"", "", ""})
|
mapper.RegisterKindFor(gvr("example.com", "v1", "widgets"), "", gvk("", "", ""))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"example.com", "v2", "widgets"}, "", schema.GroupVersionKind{"", "", ""})
|
mapper.RegisterKindFor(gvr("example.com", "v2", "widgets"), "", gvk("", "", ""))
|
||||||
|
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
|
|
||||||
|
@ -91,13 +99,13 @@ func TestMatcher(t *testing.T) {
|
||||||
attrs admission.Attributes
|
attrs admission.Attributes
|
||||||
|
|
||||||
expectMatches bool
|
expectMatches bool
|
||||||
expectMatchKind *schema.GroupVersionKind
|
expectMatchKind schema.GroupVersionKind
|
||||||
expectErr string
|
expectErr string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no rules (just write)",
|
name: "no rules (just write)",
|
||||||
criteria: &v1alpha1.MatchResources{NamespaceSelector: &metav1.LabelSelector{}, ResourceRules: []v1alpha1.NamedRuleWithOperations{}},
|
criteria: &v1alpha1.MatchResources{NamespaceSelector: &metav1.LabelSelector{}, ResourceRules: []v1alpha1.NamedRuleWithOperations{}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -111,9 +119,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"*"}, APIVersions: []string{"*"}, Resources: []string{"*"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"*"}, APIVersions: []string{"*"}, Resources: []string{"*"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"apps", "v1", "Deployment"},
|
expectMatchKind: gvk("apps", "v1", "Deployment"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, prefer exact match",
|
name: "specific rules, prefer exact match",
|
||||||
|
@ -136,9 +144,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"apps", "v1", "Deployment"},
|
expectMatchKind: gvk("apps", "v1", "Deployment"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, match miss",
|
name: "specific rules, match miss",
|
||||||
|
@ -156,7 +164,7 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -176,7 +184,7 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -196,9 +204,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"},
|
expectMatchKind: gvk("extensions", "v1beta1", "Deployment"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, equivalent match, prefer apps",
|
name: "specific rules, equivalent match, prefer apps",
|
||||||
|
@ -217,9 +225,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"apps", "v1beta1", "Deployment"},
|
expectMatchKind: gvk("apps", "v1beta1", "Deployment"),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -243,9 +251,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"autoscaling", "v1", "Scale"},
|
expectMatchKind: gvk("autoscaling", "v1", "Scale"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, subresource match miss",
|
name: "specific rules, subresource match miss",
|
||||||
|
@ -263,7 +271,7 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -283,7 +291,7 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -303,9 +311,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"extensions", "v1beta1", "Scale"},
|
expectMatchKind: gvk("extensions", "v1beta1", "Scale"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, subresource equivalent match, prefer apps",
|
name: "specific rules, subresource equivalent match, prefer apps",
|
||||||
|
@ -324,9 +332,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"apps", "v1beta1", "Scale"},
|
expectMatchKind: gvk("apps", "v1beta1", "Scale"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, prefer exact match and name match",
|
name: "specific rules, prefer exact match and name match",
|
||||||
|
@ -340,9 +348,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"autoscaling", "v1", "Scale"},
|
expectMatchKind: gvk("autoscaling", "v1", "Scale"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, prefer exact match and name match miss",
|
name: "specific rules, prefer exact match and name match miss",
|
||||||
|
@ -356,7 +364,7 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -372,9 +380,9 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("extensions", "v1beta1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"autoscaling", "v1", "Scale"},
|
expectMatchKind: gvk("autoscaling", "v1", "Scale"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "specific rules, subresource equivalent match, prefer extensions and name match miss",
|
name: "specific rules, subresource equivalent match, prefer extensions and name match miss",
|
||||||
|
@ -389,7 +397,7 @@ func TestMatcher(t *testing.T) {
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
},
|
},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("extensions", "v1beta1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -410,9 +418,9 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
expectMatchKind: &schema.GroupVersionKind{"autoscaling", "v1", "Scale"},
|
expectMatchKind: gvk("autoscaling", "v1", "Scale"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "exclude resource miss on match",
|
name: "exclude resource miss on match",
|
||||||
|
@ -432,7 +440,7 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("extensions", "v1beta1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -447,7 +455,7 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: true,
|
expectMatches: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -457,7 +465,7 @@ func TestMatcher(t *testing.T) {
|
||||||
ObjectSelector: &metav1.LabelSelector{},
|
ObjectSelector: &metav1.LabelSelector{},
|
||||||
ResourceRules: []v1alpha1.NamedRuleWithOperations{{}},
|
ResourceRules: []v1alpha1.NamedRuleWithOperations{{}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -472,7 +480,7 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, schema.GroupVersionKind{"example.apiserver.k8s.io", "v1", "Pod"}, "ns", "name", schema.GroupVersionResource{"example.apiserver.k8s.io", "v1", "pods"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, gvk("example.apiserver.k8s.io", "v1", "Pod"), "ns", "name", gvr("example.apiserver.k8s.io", "v1", "pods"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
expectErr: "",
|
expectErr: "",
|
||||||
},
|
},
|
||||||
|
@ -488,7 +496,7 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, schema.GroupVersionKind{"example.apiserver.k8s.io", "v1", "Pod"}, "ns", "name", schema.GroupVersionResource{"example.apiserver.k8s.io", "v1", "pods"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, gvk("example.apiserver.k8s.io", "v1", "Pod"), "ns", "name", gvr("example.apiserver.k8s.io", "v1", "pods"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
expectErr: "bad value",
|
expectErr: "bad value",
|
||||||
},
|
},
|
||||||
|
@ -504,7 +512,7 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, schema.GroupVersionKind{"example.apiserver.k8s.io", "v1", "Pod"}, "ns", "name", schema.GroupVersionResource{"example.apiserver.k8s.io", "v1", "pods"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, gvk("example.apiserver.k8s.io", "v1", "Pod"), "ns", "name", gvr("example.apiserver.k8s.io", "v1", "pods"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
expectErr: "",
|
expectErr: "",
|
||||||
},
|
},
|
||||||
|
@ -520,7 +528,7 @@ func TestMatcher(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, schema.GroupVersionKind{"example.apiserver.k8s.io", "v1", "Pod"}, "ns", "name", schema.GroupVersionResource{"example.apiserver.k8s.io", "v1", "pods"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(&example.Pod{}, nil, gvk("example.apiserver.k8s.io", "v1", "Pod"), "ns", "name", gvr("example.apiserver.k8s.io", "v1", "pods"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectMatches: false,
|
expectMatches: false,
|
||||||
expectErr: "bad value",
|
expectErr: "bad value",
|
||||||
},
|
},
|
||||||
|
@ -540,8 +548,9 @@ func TestMatcher(t *testing.T) {
|
||||||
} else if len(testcase.expectErr) > 0 {
|
} else if len(testcase.expectErr) > 0 {
|
||||||
t.Fatalf("expected error %q, got no error", testcase.expectErr)
|
t.Fatalf("expected error %q, got no error", testcase.expectErr)
|
||||||
}
|
}
|
||||||
if testcase.expectMatchKind != nil {
|
var emptyGVK schema.GroupVersionKind
|
||||||
if *testcase.expectMatchKind != matchKind {
|
if testcase.expectMatchKind != emptyGVK {
|
||||||
|
if testcase.expectMatchKind != matchKind {
|
||||||
t.Fatalf("expected matchKind %v, got %v", testcase.expectMatchKind, matchKind)
|
t.Fatalf("expected matchKind %v, got %v", testcase.expectMatchKind, matchKind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,23 +597,23 @@ func BenchmarkMatcher(b *testing.B) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "", gvk("apps", "v1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "", gvk("apps", "v1beta1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta2", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta2", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta2", "statefulset"), "", gvk("apps", "v1beta2", "StatefulSet"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "scale", gvk("apps", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha2", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta2", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha2", "statefulset"), "scale", gvk("apps", "v1beta2", "Scale"))
|
||||||
|
|
||||||
nsSelector := make(map[string]string)
|
nsSelector := make(map[string]string)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
@ -632,7 +641,7 @@ func BenchmarkMatcher(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := &fakeCriteria{matchResources: mr}
|
criteria := &fakeCriteria{matchResources: mr}
|
||||||
attrs := admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
attrs := admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
matcher := &Matcher{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
matcher := &Matcher{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
@ -661,23 +670,23 @@ func BenchmarkShouldCallHookWithComplexRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "", gvk("apps", "v1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "", gvk("apps", "v1beta1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta2", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta2", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta2", "statefulset"), "", gvk("apps", "v1beta2", "StatefulSet"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "scale", gvk("apps", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha2", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta2", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha2", "statefulset"), "scale", gvk("apps", "v1beta2", "Scale"))
|
||||||
|
|
||||||
mr := v1alpha1.MatchResources{
|
mr := v1alpha1.MatchResources{
|
||||||
MatchPolicy: &equivalentMatch,
|
MatchPolicy: &equivalentMatch,
|
||||||
|
@ -702,7 +711,7 @@ func BenchmarkShouldCallHookWithComplexRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := &fakeCriteria{matchResources: mr}
|
criteria := &fakeCriteria{matchResources: mr}
|
||||||
attrs := admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
attrs := admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
matcher := &Matcher{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
matcher := &Matcher{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
@ -731,23 +740,23 @@ func BenchmarkShouldCallHookWithComplexSelectorAndRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "", gvk("apps", "v1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "", gvk("apps", "v1beta1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta2", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta2", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta2", "statefulset"), "", gvk("apps", "v1beta2", "StatefulSet"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "scale", gvk("apps", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha2", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta2", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha2", "statefulset"), "scale", gvk("apps", "v1beta2", "Scale"))
|
||||||
|
|
||||||
nsSelector := make(map[string]string)
|
nsSelector := make(map[string]string)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
@ -777,7 +786,7 @@ func BenchmarkShouldCallHookWithComplexSelectorAndRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := &fakeCriteria{matchResources: mr}
|
criteria := &fakeCriteria{matchResources: mr}
|
||||||
attrs := admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
attrs := admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
matcher := &Matcher{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
matcher := &Matcher{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ func TestConvertVersionedAttributes(t *testing.T) {
|
||||||
o := admission.NewObjectInterfacesFromScheme(scheme)
|
o := admission.NewObjectInterfacesFromScheme(scheme)
|
||||||
|
|
||||||
gvk := func(g, v, k string) schema.GroupVersionKind {
|
gvk := func(g, v, k string) schema.GroupVersionKind {
|
||||||
return schema.GroupVersionKind{g, v, k}
|
return schema.GroupVersionKind{Group: g, Version: v, Kind: k}
|
||||||
}
|
}
|
||||||
attrs := func(obj, oldObj runtime.Object) admission.Attributes {
|
attrs := func(obj, oldObj runtime.Object) admission.Attributes {
|
||||||
return admission.NewAttributesRecord(obj, oldObj, schema.GroupVersionKind{}, "", "", schema.GroupVersionResource{}, "", "", nil, false, nil)
|
return admission.NewAttributesRecord(obj, oldObj, schema.GroupVersionKind{}, "", "", schema.GroupVersionResource{}, "", "", nil, false, nil)
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/admissionregistration/v1"
|
v1 "k8s.io/api/admissionregistration/v1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
@ -34,6 +34,14 @@ import (
|
||||||
"k8s.io/apiserver/pkg/admission/plugin/webhook/predicates/object"
|
"k8s.io/apiserver/pkg/admission/plugin/webhook/predicates/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func gvr(group, version, resource string) schema.GroupVersionResource {
|
||||||
|
return schema.GroupVersionResource{Group: group, Version: version, Resource: resource}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gvk(group, version, kind string) schema.GroupVersionKind {
|
||||||
|
return schema.GroupVersionKind{Group: group, Version: version, Kind: kind}
|
||||||
|
}
|
||||||
|
|
||||||
func TestShouldCallHook(t *testing.T) {
|
func TestShouldCallHook(t *testing.T) {
|
||||||
a := &Webhook{namespaceMatcher: &namespace.Matcher{}, objectMatcher: &object.Matcher{}}
|
a := &Webhook{namespaceMatcher: &namespace.Matcher{}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
@ -48,19 +56,19 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
// register invalid kinds to trigger an error
|
// register invalid kinds to trigger an error
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"example.com", "v1", "widgets"}, "", schema.GroupVersionKind{"", "", ""})
|
mapper.RegisterKindFor(gvr("example.com", "v1", "widgets"), "", gvk("", "", ""))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"example.com", "v2", "widgets"}, "", schema.GroupVersionKind{"", "", ""})
|
mapper.RegisterKindFor(gvr("example.com", "v2", "widgets"), "", gvk("", "", ""))
|
||||||
|
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
|
|
||||||
|
@ -79,7 +87,7 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "no rules (just write)",
|
name: "no rules (just write)",
|
||||||
webhook: &v1.ValidatingWebhook{NamespaceSelector: &metav1.LabelSelector{}, Rules: []v1.RuleWithOperations{}},
|
webhook: &v1.ValidatingWebhook{NamespaceSelector: &metav1.LabelSelector{}, Rules: []v1.RuleWithOperations{}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: false,
|
expectCall: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -92,7 +100,7 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"example.com"}, APIVersions: []string{"v1"}, Resources: []string{"widgets"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"example.com"}, APIVersions: []string{"v1"}, Resources: []string{"widgets"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"example.com", "v2", "Widget"}, "ns", "name", schema.GroupVersionResource{"example.com", "v2", "widgets"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("example.com", "v2", "Widget"), "ns", "name", gvr("example.com", "v2", "widgets"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: false,
|
expectCall: false,
|
||||||
expectErr: "unknown kind",
|
expectErr: "unknown kind",
|
||||||
},
|
},
|
||||||
|
@ -105,10 +113,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"*"}, APIVersions: []string{"*"}, Resources: []string{"*"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"*"}, APIVersions: []string{"*"}, Resources: []string{"*"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"apps", "v1", "Deployment"},
|
expectCallKind: gvk("apps", "v1", "Deployment"),
|
||||||
expectCallResource: schema.GroupVersionResource{"apps", "v1", "deployments"},
|
expectCallResource: gvr("apps", "v1", "deployments"),
|
||||||
expectCallSubresource: "",
|
expectCallSubresource: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -126,10 +134,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"apps", "v1", "Deployment"},
|
expectCallKind: gvk("apps", "v1", "Deployment"),
|
||||||
expectCallResource: schema.GroupVersionResource{"apps", "v1", "deployments"},
|
expectCallResource: gvr("apps", "v1", "deployments"),
|
||||||
expectCallSubresource: "",
|
expectCallSubresource: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -144,7 +152,7 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: false,
|
expectCall: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -160,7 +168,7 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: false,
|
expectCall: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -176,10 +184,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"},
|
expectCallKind: gvk("extensions", "v1beta1", "Deployment"),
|
||||||
expectCallResource: schema.GroupVersionResource{"extensions", "v1beta1", "deployments"},
|
expectCallResource: gvr("extensions", "v1beta1", "deployments"),
|
||||||
expectCallSubresource: "",
|
expectCallSubresource: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -195,10 +203,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"apps", "v1", "Deployment"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("apps", "v1", "Deployment"), "ns", "name", gvr("apps", "v1", "deployments"), "", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"apps", "v1beta1", "Deployment"},
|
expectCallKind: gvk("apps", "v1beta1", "Deployment"),
|
||||||
expectCallResource: schema.GroupVersionResource{"apps", "v1beta1", "deployments"},
|
expectCallResource: gvr("apps", "v1beta1", "deployments"),
|
||||||
expectCallSubresource: "",
|
expectCallSubresource: "",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -217,10 +225,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"autoscaling", "v1", "Scale"},
|
expectCallKind: gvk("autoscaling", "v1", "Scale"),
|
||||||
expectCallResource: schema.GroupVersionResource{"apps", "v1", "deployments"},
|
expectCallResource: gvr("apps", "v1", "deployments"),
|
||||||
expectCallSubresource: "scale",
|
expectCallSubresource: "scale",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -235,7 +243,7 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: false,
|
expectCall: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -251,7 +259,7 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: false,
|
expectCall: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -267,10 +275,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"apps"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"extensions", "v1beta1", "Scale"},
|
expectCallKind: gvk("extensions", "v1beta1", "Scale"),
|
||||||
expectCallResource: schema.GroupVersionResource{"extensions", "v1beta1", "deployments"},
|
expectCallResource: gvr("extensions", "v1beta1", "deployments"),
|
||||||
expectCallSubresource: "scale",
|
expectCallSubresource: "scale",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -286,10 +294,10 @@ func TestShouldCallHook(t *testing.T) {
|
||||||
Operations: []v1.OperationType{"*"},
|
Operations: []v1.OperationType{"*"},
|
||||||
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
Rule: v1.Rule{APIGroups: []string{"extensions"}, APIVersions: []string{"v1beta1"}, Resources: []string{"deployments", "deployments/scale"}, Scope: &allScopes},
|
||||||
}}},
|
}}},
|
||||||
attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
attrs: admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil),
|
||||||
expectCall: true,
|
expectCall: true,
|
||||||
expectCallKind: schema.GroupVersionKind{"apps", "v1beta1", "Scale"},
|
expectCallKind: gvk("apps", "v1beta1", "Scale"),
|
||||||
expectCallResource: schema.GroupVersionResource{"apps", "v1beta1", "deployments"},
|
expectCallResource: gvr("apps", "v1beta1", "deployments"),
|
||||||
expectCallSubresource: "scale",
|
expectCallSubresource: "scale",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -368,23 +376,23 @@ func BenchmarkShouldCallHookWithComplexSelector(b *testing.B) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "", gvk("apps", "v1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "", gvk("apps", "v1beta1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta2", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta2", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta2", "statefulset"), "", gvk("apps", "v1beta2", "StatefulSet"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "scale", gvk("apps", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha2", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta2", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha2", "statefulset"), "scale", gvk("apps", "v1beta2", "Scale"))
|
||||||
|
|
||||||
nsSelector := make(map[string]string)
|
nsSelector := make(map[string]string)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
@ -408,7 +416,7 @@ func BenchmarkShouldCallHookWithComplexSelector(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wbAccessor := webhook.NewValidatingWebhookAccessor("webhook", "webhook-cfg", wb)
|
wbAccessor := webhook.NewValidatingWebhookAccessor("webhook", "webhook-cfg", wb)
|
||||||
attrs := admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
attrs := admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
a := &Webhook{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
a := &Webhook{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
@ -437,23 +445,23 @@ func BenchmarkShouldCallHookWithComplexRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "", gvk("apps", "v1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "", gvk("apps", "v1beta1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta2", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta2", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta2", "statefulset"), "", gvk("apps", "v1beta2", "StatefulSet"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "scale", gvk("apps", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha2", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta2", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha2", "statefulset"), "scale", gvk("apps", "v1beta2", "Scale"))
|
||||||
|
|
||||||
wb := &v1.ValidatingWebhook{
|
wb := &v1.ValidatingWebhook{
|
||||||
MatchPolicy: &equivalentMatch,
|
MatchPolicy: &equivalentMatch,
|
||||||
|
@ -476,7 +484,7 @@ func BenchmarkShouldCallHookWithComplexRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wbAccessor := webhook.NewValidatingWebhookAccessor("webhook", "webhook-cfg", wb)
|
wbAccessor := webhook.NewValidatingWebhookAccessor("webhook", "webhook-cfg", wb)
|
||||||
attrs := admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
attrs := admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
a := &Webhook{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
a := &Webhook{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
@ -505,23 +513,23 @@ func BenchmarkShouldCallHookWithComplexSelectorAndRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"extensions", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "", gvk("extensions", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "", gvk("apps", "v1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1beta1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "", gvk("apps", "v1beta1", "Deployment"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "", schema.GroupVersionKind{"apps", "v1alpha1", "Deployment"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "", gvk("apps", "v1alpha1", "Deployment"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"extensions", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"extensions", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("extensions", "v1beta1", "deployments"), "scale", gvk("extensions", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", schema.GroupVersionKind{"autoscaling", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "deployments"), "scale", gvk("autoscaling", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "deployments"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha1", "deployments"}, "scale", schema.GroupVersionKind{"apps", "v1alpha1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha1", "deployments"), "scale", gvk("apps", "v1alpha1", "Scale"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "", gvk("apps", "v1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta1", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "", gvk("apps", "v1beta1", "StatefulSet"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta2", "statefulset"}, "", schema.GroupVersionKind{"apps", "v1beta2", "StatefulSet"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta2", "statefulset"), "", gvk("apps", "v1beta2", "StatefulSet"))
|
||||||
|
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1", "statefulset"), "scale", gvk("apps", "v1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1beta1", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta1", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1beta1", "statefulset"), "scale", gvk("apps", "v1beta1", "Scale"))
|
||||||
mapper.RegisterKindFor(schema.GroupVersionResource{"apps", "v1alpha2", "statefulset"}, "scale", schema.GroupVersionKind{"apps", "v1beta2", "Scale"})
|
mapper.RegisterKindFor(gvr("apps", "v1alpha2", "statefulset"), "scale", gvk("apps", "v1beta2", "Scale"))
|
||||||
|
|
||||||
nsSelector := make(map[string]string)
|
nsSelector := make(map[string]string)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
@ -549,7 +557,7 @@ func BenchmarkShouldCallHookWithComplexSelectorAndRule(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wbAccessor := webhook.NewValidatingWebhookAccessor("webhook", "webhook-cfg", wb)
|
wbAccessor := webhook.NewValidatingWebhookAccessor("webhook", "webhook-cfg", wb)
|
||||||
attrs := admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{"autoscaling", "v1", "Scale"}, "ns", "name", schema.GroupVersionResource{"apps", "v1", "deployments"}, "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
attrs := admission.NewAttributesRecord(nil, nil, gvk("autoscaling", "v1", "Scale"), "ns", "name", gvr("apps", "v1", "deployments"), "scale", admission.Create, &metav1.CreateOptions{}, false, nil)
|
||||||
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
interfaces := &admission.RuntimeObjectInterfaces{EquivalentResourceMapper: mapper}
|
||||||
a := &Webhook{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
a := &Webhook{namespaceMatcher: &namespace.Matcher{NamespaceLister: namespaceLister}, objectMatcher: &object.Matcher{}}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (m *Matcher) MatchNamespaceSelector(p NamespaceSelectorProvider, attr admis
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, apierrors.NewInternalError(err)
|
return false, apierrors.NewInternalError(err)
|
||||||
}
|
}
|
||||||
return false, &apierrors.StatusError{status.Status()}
|
return false, &apierrors.StatusError{ErrStatus: status.Status()}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, apierrors.NewInternalError(err)
|
return false, apierrors.NewInternalError(err)
|
||||||
|
|
|
@ -297,7 +297,18 @@ func ConvertToMutatingTestCases(tests []ValidatingTest, configurationName string
|
||||||
func ConvertToMutatingWebhooks(webhooks []registrationv1.ValidatingWebhook) []registrationv1.MutatingWebhook {
|
func ConvertToMutatingWebhooks(webhooks []registrationv1.ValidatingWebhook) []registrationv1.MutatingWebhook {
|
||||||
mutating := make([]registrationv1.MutatingWebhook, len(webhooks))
|
mutating := make([]registrationv1.MutatingWebhook, len(webhooks))
|
||||||
for i, h := range webhooks {
|
for i, h := range webhooks {
|
||||||
mutating[i] = registrationv1.MutatingWebhook{h.Name, h.ClientConfig, h.Rules, h.FailurePolicy, h.MatchPolicy, h.NamespaceSelector, h.ObjectSelector, h.SideEffects, h.TimeoutSeconds, h.AdmissionReviewVersions, nil}
|
mutating[i] = registrationv1.MutatingWebhook{
|
||||||
|
Name: h.Name,
|
||||||
|
ClientConfig: h.ClientConfig,
|
||||||
|
Rules: h.Rules,
|
||||||
|
FailurePolicy: h.FailurePolicy,
|
||||||
|
MatchPolicy: h.MatchPolicy,
|
||||||
|
NamespaceSelector: h.NamespaceSelector,
|
||||||
|
ObjectSelector: h.ObjectSelector,
|
||||||
|
SideEffects: h.SideEffects,
|
||||||
|
TimeoutSeconds: h.TimeoutSeconds,
|
||||||
|
AdmissionReviewVersions: h.AdmissionReviewVersions,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mutating
|
return mutating
|
||||||
}
|
}
|
||||||
|
|
|
@ -2085,7 +2085,7 @@ func watcher(mediaType string, r io.ReadCloser) streaming.Decoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPartialObjectMetadata(t *testing.T) {
|
func TestGetPartialObjectMetadata(t *testing.T) {
|
||||||
now := metav1.Time{metav1.Now().Rfc3339Copy().Local()}
|
now := metav1.Time{Time: metav1.Now().Rfc3339Copy().Local()}
|
||||||
storage := map[string]rest.Storage{}
|
storage := map[string]rest.Storage{}
|
||||||
simpleStorage := SimpleRESTStorage{
|
simpleStorage := SimpleRESTStorage{
|
||||||
item: genericapitesting.Simple{
|
item: genericapitesting.Simple{
|
||||||
|
|
|
@ -100,13 +100,13 @@ func WithStorageVersionPrecondition(handler http.Handler, svm storageversion.Man
|
||||||
}
|
}
|
||||||
// If the resource's StorageVersion is not in the to-be-updated list, let it pass.
|
// If the resource's StorageVersion is not in the to-be-updated list, let it pass.
|
||||||
// Non-persisted resources are not in the to-be-updated list, so they will pass.
|
// Non-persisted resources are not in the to-be-updated list, so they will pass.
|
||||||
gr := schema.GroupResource{requestInfo.APIGroup, requestInfo.Resource}
|
gr := schema.GroupResource{Group: requestInfo.APIGroup, Resource: requestInfo.Resource}
|
||||||
if !svm.PendingUpdate(gr) {
|
if !svm.PendingUpdate(gr) {
|
||||||
handler.ServeHTTP(w, req)
|
handler.ServeHTTP(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gv := schema.GroupVersion{requestInfo.APIGroup, requestInfo.APIVersion}
|
gv := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
|
||||||
responsewriters.ErrorNegotiated(apierrors.NewServiceUnavailable(fmt.Sprintf("wait for storage version registration to complete for resource: %v, last seen error: %v", gr, svm.LastUpdateError(gr))), s, gv, w, req)
|
responsewriters.ErrorNegotiated(apierrors.NewServiceUnavailable(fmt.Sprintf("wait for storage version registration to complete for resource: %v, last seen error: %v", gr, svm.LastUpdateError(gr))), s, gv, w, req)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -851,7 +851,7 @@ func TestUpdateViaSubresources(t *testing.T) {
|
||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
FieldsType: "FieldsV1",
|
FieldsType: "FieldsV1",
|
||||||
FieldsV1: &metav1.FieldsV1{
|
FieldsV1: &metav1.FieldsV1{
|
||||||
[]byte(`{"f:metadata":{"f:labels":{"f:another_field":{}}}}`),
|
Raw: []byte(`{"f:metadata":{"f:labels":{"f:another_field":{}}}}`),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,7 +45,6 @@ func (*fakeManager) Update(_, newObj runtime.Object, managed internal.Managed, _
|
||||||
|
|
||||||
func (*fakeManager) Apply(_, _ runtime.Object, _ internal.Managed, _ string, _ bool) (runtime.Object, internal.Managed, error) {
|
func (*fakeManager) Apply(_, _ runtime.Object, _ internal.Managed, _ string, _ bool) (runtime.Object, internal.Managed, error) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
return nil, nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCapManagersManagerMergesEntries(t *testing.T) {
|
func TestCapManagersManagerMergesEntries(t *testing.T) {
|
||||||
|
|
|
@ -473,14 +473,14 @@ func TestSortEncodedManagedFields(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "sort drops nanoseconds",
|
name: "sort drops nanoseconds",
|
||||||
managedFields: []metav1.ManagedFieldsEntry{
|
managedFields: []metav1.ManagedFieldsEntry{
|
||||||
{Manager: "c", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{time.Date(2000, time.January, 0, 0, 0, 0, 1, time.UTC)}},
|
{Manager: "c", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{Time: time.Date(2000, time.January, 0, 0, 0, 0, 1, time.UTC)}},
|
||||||
{Manager: "a", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{time.Date(2000, time.January, 0, 0, 0, 0, 2, time.UTC)}},
|
{Manager: "a", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{Time: time.Date(2000, time.January, 0, 0, 0, 0, 2, time.UTC)}},
|
||||||
{Manager: "b", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{time.Date(2000, time.January, 0, 0, 0, 0, 3, time.UTC)}},
|
{Manager: "b", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{Time: time.Date(2000, time.January, 0, 0, 0, 0, 3, time.UTC)}},
|
||||||
},
|
},
|
||||||
expected: []metav1.ManagedFieldsEntry{
|
expected: []metav1.ManagedFieldsEntry{
|
||||||
{Manager: "a", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{time.Date(2000, time.January, 0, 0, 0, 0, 2, time.UTC)}},
|
{Manager: "a", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{Time: time.Date(2000, time.January, 0, 0, 0, 0, 2, time.UTC)}},
|
||||||
{Manager: "b", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{time.Date(2000, time.January, 0, 0, 0, 0, 3, time.UTC)}},
|
{Manager: "b", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{Time: time.Date(2000, time.January, 0, 0, 0, 0, 3, time.UTC)}},
|
||||||
{Manager: "c", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{time.Date(2000, time.January, 0, 0, 0, 0, 1, time.UTC)}},
|
{Manager: "c", Operation: metav1.ManagedFieldsOperationUpdate, Time: &metav1.Time{Time: time.Date(2000, time.January, 0, 0, 0, 0, 1, time.UTC)}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -729,13 +729,8 @@ func setupInFlightWatchRequestHandler(s *GenericAPIServer) *inFlightRequest {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
select {
|
<-signals.ShuttingDown()
|
||||||
case <-signals.ShuttingDown():
|
w.WriteHeader(http.StatusOK)
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
})
|
})
|
||||||
s.Handler.NonGoRestfulMux.Handle("/apis/watches.group/v1/namespaces/foo/bar", handler)
|
s.Handler.NonGoRestfulMux.Handle("/apis/watches.group/v1/namespaces/foo/bar", handler)
|
||||||
return inflight
|
return inflight
|
||||||
|
|
|
@ -678,7 +678,7 @@ func TestKMSPluginHealthz(t *testing.T) {
|
||||||
p.service = nil
|
p.service = nil
|
||||||
p.l = nil
|
p.l = nil
|
||||||
p.lastResponse = nil
|
p.lastResponse = nil
|
||||||
p.keyID = kmsv2Probe.keyID
|
p.keyID.Store(kmsv2Probe.keyID.Load())
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected probe type %T", p)
|
t.Fatalf("unexpected probe type %T", p)
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,6 +230,7 @@ func (s *EtcdOptions) Complete(
|
||||||
|
|
||||||
if len(s.EncryptionProviderConfigFilepath) != 0 {
|
if len(s.EncryptionProviderConfigFilepath) != 0 {
|
||||||
ctxServer := wait.ContextForChannel(stopCh)
|
ctxServer := wait.ContextForChannel(stopCh)
|
||||||
|
// nolint:govet // The only code path where closeTransformers does not get called is when it gets stored in dynamicTransformers.
|
||||||
ctxTransformers, closeTransformers := context.WithCancel(ctxServer)
|
ctxTransformers, closeTransformers := context.WithCancel(ctxServer)
|
||||||
|
|
||||||
encryptionConfiguration, err := encryptionconfig.LoadEncryptionConfig(ctxTransformers, s.EncryptionProviderConfigFilepath, s.EncryptionProviderConfigAutomaticReload)
|
encryptionConfiguration, err := encryptionconfig.LoadEncryptionConfig(ctxTransformers, s.EncryptionProviderConfigFilepath, s.EncryptionProviderConfigAutomaticReload)
|
||||||
|
@ -248,6 +249,7 @@ func (s *EtcdOptions) Complete(
|
||||||
return fmt.Errorf("failed to start kms encryption config hot reload controller. only 1 health check should be available when reload is enabled")
|
return fmt.Errorf("failed to start kms encryption config hot reload controller. only 1 health check should be available when reload is enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Here the dynamic transformers take ownership of the transformers and their cancellation.
|
||||||
dynamicTransformers := encryptionconfig.NewDynamicTransformers(encryptionConfiguration.Transformers, encryptionConfiguration.HealthChecks[0], closeTransformers, encryptionConfiguration.KMSCloseGracePeriod)
|
dynamicTransformers := encryptionconfig.NewDynamicTransformers(encryptionConfiguration.Transformers, encryptionConfiguration.HealthChecks[0], closeTransformers, encryptionConfiguration.KMSCloseGracePeriod)
|
||||||
|
|
||||||
// add post start hook to start hot reload controller
|
// add post start hook to start hot reload controller
|
||||||
|
@ -285,6 +287,7 @@ func (s *EtcdOptions) Complete(
|
||||||
|
|
||||||
s.complete = true
|
s.complete = true
|
||||||
|
|
||||||
|
// nolint:govet // The only code path where closeTransformers does not get called is when it gets stored in dynamicTransformers.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,8 @@ func RunTestWatchContextCancel(ctx context.Context, t *testing.T, store storage.
|
||||||
func RunTestWatchDeleteEventObjectHaveLatestRV(ctx context.Context, t *testing.T, store storage.Interface) {
|
func RunTestWatchDeleteEventObjectHaveLatestRV(ctx context.Context, t *testing.T, store storage.Interface) {
|
||||||
key, storedObj := testPropagateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "test-ns"}})
|
key, storedObj := testPropagateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "test-ns"}})
|
||||||
|
|
||||||
watchCtx, _ := context.WithTimeout(ctx, wait.ForeverTestTimeout)
|
watchCtx, cancel := context.WithTimeout(ctx, wait.ForeverTestTimeout)
|
||||||
|
t.Cleanup(cancel)
|
||||||
w, err := store.Watch(watchCtx, key, storage.ListOptions{ResourceVersion: storedObj.ResourceVersion, Predicate: storage.Everything})
|
w, err := store.Watch(watchCtx, key, storage.ListOptions{ResourceVersion: storedObj.ResourceVersion, Predicate: storage.Everything})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Watch failed: %v", err)
|
t.Fatalf("Watch failed: %v", err)
|
||||||
|
@ -314,7 +315,8 @@ func RunTestWatchDeleteEventObjectHaveLatestRV(ctx context.Context, t *testing.T
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunTestWatchInitializationSignal(ctx context.Context, t *testing.T, store storage.Interface) {
|
func RunTestWatchInitializationSignal(ctx context.Context, t *testing.T, store storage.Interface) {
|
||||||
ctx, _ = context.WithTimeout(ctx, 5*time.Second)
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
t.Cleanup(cancel)
|
||||||
initSignal := utilflowcontrol.NewInitializationSignal()
|
initSignal := utilflowcontrol.NewInitializationSignal()
|
||||||
ctx = utilflowcontrol.WithInitializationSignal(ctx, initSignal)
|
ctx = utilflowcontrol.WithInitializationSignal(ctx, initSignal)
|
||||||
|
|
||||||
|
|
|
@ -655,7 +655,8 @@ func TestWatchDispatchBookmarkEvents(t *testing.T) {
|
||||||
for i, c := range tests {
|
for i, c := range tests {
|
||||||
pred := storage.Everything
|
pred := storage.Everything
|
||||||
pred.AllowWatchBookmarks = c.allowWatchBookmark
|
pred.AllowWatchBookmarks = c.allowWatchBookmark
|
||||||
ctx, _ := context.WithTimeout(context.Background(), c.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
|
||||||
|
t.Cleanup(cancel)
|
||||||
watcher, err := cacher.Watch(ctx, "pods/ns/foo", storage.ListOptions{ResourceVersion: startVersion, Predicate: pred})
|
watcher, err := cacher.Watch(ctx, "pods/ns/foo", storage.ListOptions{ResourceVersion: startVersion, Predicate: pred})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
@ -695,7 +696,8 @@ func TestWatchBookmarksWithCorrectResourceVersion(t *testing.T) {
|
||||||
|
|
||||||
pred := storage.Everything
|
pred := storage.Everything
|
||||||
pred.AllowWatchBookmarks = true
|
pred.AllowWatchBookmarks = true
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
t.Cleanup(cancel)
|
||||||
watcher, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred, Recursive: true})
|
watcher, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred, Recursive: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
|
|
@ -144,7 +144,8 @@ func TestTimeouts(t *testing.T) {
|
||||||
|
|
||||||
service, err = NewGRPCService(ctx, socketName.endpoint, tt.callTimeout)
|
service, err = NewGRPCService(ctx, socketName.endpoint, tt.callTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create envelope service, error: %v", err)
|
t.Errorf("failed to create envelope service, error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer destroyService(service)
|
defer destroyService(service)
|
||||||
kubeAPIServerWG.Done()
|
kubeAPIServerWG.Done()
|
||||||
|
@ -159,10 +160,12 @@ func TestTimeouts(t *testing.T) {
|
||||||
|
|
||||||
f, err := mock.NewBase64Plugin(socketName.path)
|
f, err := mock.NewBase64Plugin(socketName.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to construct test KMS provider server, error: %v", err)
|
t.Errorf("failed to construct test KMS provider server, error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if err := f.Start(); err != nil {
|
if err := f.Start(); err != nil {
|
||||||
t.Fatalf("Failed to start test KMS provider server, error: %v", err)
|
t.Errorf("Failed to start test KMS provider server, error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer f.CleanUp()
|
defer f.CleanUp()
|
||||||
kmsPluginWG.Done()
|
kmsPluginWG.Done()
|
||||||
|
@ -171,6 +174,9 @@ func TestTimeouts(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
kubeAPIServerWG.Wait()
|
kubeAPIServerWG.Wait()
|
||||||
|
if t.Failed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
_, err = service.Encrypt(data)
|
_, err = service.Encrypt(data)
|
||||||
|
|
||||||
if err == nil && tt.wantErr != "" {
|
if err == nil && tt.wantErr != "" {
|
||||||
|
|
|
@ -404,6 +404,7 @@ func TestValidateAnnotations(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Run("success", func(t *testing.T) {
|
t.Run("success", func(t *testing.T) {
|
||||||
for i := range successCases {
|
for i := range successCases {
|
||||||
|
i := i
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if err := validateAnnotations(successCases[i]); err != nil {
|
if err := validateAnnotations(successCases[i]); err != nil {
|
||||||
|
@ -441,6 +442,7 @@ func TestValidateAnnotations(t *testing.T) {
|
||||||
|
|
||||||
t.Run("name error", func(t *testing.T) {
|
t.Run("name error", func(t *testing.T) {
|
||||||
for i := range annotationsNameErrorCases {
|
for i := range annotationsNameErrorCases {
|
||||||
|
i := i
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
err := validateAnnotations(annotationsNameErrorCases[i].annotations)
|
err := validateAnnotations(annotationsNameErrorCases[i].annotations)
|
||||||
|
@ -468,6 +470,7 @@ func TestValidateAnnotations(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Run("size error", func(t *testing.T) {
|
t.Run("size error", func(t *testing.T) {
|
||||||
for i := range annotationsSizeErrorCases {
|
for i := range annotationsSizeErrorCases {
|
||||||
|
i := i
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
err := validateAnnotations(annotationsSizeErrorCases[i].annotations)
|
err := validateAnnotations(annotationsSizeErrorCases[i].annotations)
|
||||||
|
|
|
@ -149,7 +149,8 @@ func TestTimeouts(t *testing.T) {
|
||||||
|
|
||||||
service, err = NewGRPCService(ctx, socketName.endpoint, testProviderName, tt.callTimeout)
|
service, err = NewGRPCService(ctx, socketName.endpoint, testProviderName, tt.callTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create envelope service, error: %v", err)
|
t.Errorf("failed to create envelope service, error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer destroyService(service)
|
defer destroyService(service)
|
||||||
kubeAPIServerWG.Done()
|
kubeAPIServerWG.Done()
|
||||||
|
@ -164,10 +165,12 @@ func TestTimeouts(t *testing.T) {
|
||||||
|
|
||||||
f, err := mock.NewBase64Plugin(socketName.path)
|
f, err := mock.NewBase64Plugin(socketName.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to construct test KMS provider server, error: %v", err)
|
t.Errorf("failed to construct test KMS provider server, error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if err := f.Start(); err != nil {
|
if err := f.Start(); err != nil {
|
||||||
t.Fatalf("Failed to start test KMS provider server, error: %v", err)
|
t.Errorf("Failed to start test KMS provider server, error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer f.CleanUp()
|
defer f.CleanUp()
|
||||||
kmsPluginWG.Done()
|
kmsPluginWG.Done()
|
||||||
|
@ -176,6 +179,9 @@ func TestTimeouts(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
kubeAPIServerWG.Wait()
|
kubeAPIServerWG.Wait()
|
||||||
|
if t.Failed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
_, err = service.Encrypt(ctx, uid, data)
|
_, err = service.Encrypt(ctx, uid, data)
|
||||||
|
|
||||||
if err == nil && tt.wantErr != "" {
|
if err == nil && tt.wantErr != "" {
|
||||||
|
|
|
@ -208,9 +208,9 @@ func genFS(t *testing.T, rng *rand.Rand, name string, mayMatchClusterScope bool,
|
||||||
}
|
}
|
||||||
dangleStatus := flowcontrol.ConditionFalse
|
dangleStatus := flowcontrol.ConditionFalse
|
||||||
if rng.Float32() < 0.9 && len(goodPLNames) > 0 {
|
if rng.Float32() < 0.9 && len(goodPLNames) > 0 {
|
||||||
fs.Spec.PriorityLevelConfiguration = flowcontrol.PriorityLevelConfigurationReference{pickSetString(rng, goodPLNames)}
|
fs.Spec.PriorityLevelConfiguration = flowcontrol.PriorityLevelConfigurationReference{Name: pickSetString(rng, goodPLNames)}
|
||||||
} else {
|
} else {
|
||||||
fs.Spec.PriorityLevelConfiguration = flowcontrol.PriorityLevelConfigurationReference{pickSetString(rng, badPLNames)}
|
fs.Spec.PriorityLevelConfiguration = flowcontrol.PriorityLevelConfigurationReference{Name: pickSetString(rng, badPLNames)}
|
||||||
ftr.wellFormed = false
|
ftr.wellFormed = false
|
||||||
dangleStatus = flowcontrol.ConditionTrue
|
dangleStatus = flowcontrol.ConditionTrue
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ func genFS(t *testing.T, rng *rand.Rand, name string, mayMatchClusterScope bool,
|
||||||
fs.Spec.MatchingPrecedence = rng.Int31n(9997) + 2
|
fs.Spec.MatchingPrecedence = rng.Int31n(9997) + 2
|
||||||
if rng.Float32() < 0.8 {
|
if rng.Float32() < 0.8 {
|
||||||
fdmt := flowcontrol.FlowDistinguisherMethodType(pickSetString(rng, flowDistinguisherMethodTypes))
|
fdmt := flowcontrol.FlowDistinguisherMethodType(pickSetString(rng, flowDistinguisherMethodTypes))
|
||||||
fs.Spec.DistinguisherMethod = &flowcontrol.FlowDistinguisherMethod{fdmt}
|
fs.Spec.DistinguisherMethod = &flowcontrol.FlowDistinguisherMethod{Type: fdmt}
|
||||||
}
|
}
|
||||||
fs.Spec.Rules = []flowcontrol.PolicyRulesWithSubjects{}
|
fs.Spec.Rules = []flowcontrol.PolicyRulesWithSubjects{}
|
||||||
everyResourceMatcher := -1
|
everyResourceMatcher := -1
|
||||||
|
@ -347,7 +347,7 @@ func genPolicyRuleWithSubjects(t *testing.T, rng *rand.Rand, pfx string, mayMatc
|
||||||
if nRR == 0 {
|
if nRR == 0 {
|
||||||
_, _, skippingNRIs = genNonResourceRule(rng, pfx+"-o", false, someMatchesAllNonResourceRequests)
|
_, _, skippingNRIs = genNonResourceRule(rng, pfx+"-o", false, someMatchesAllNonResourceRequests)
|
||||||
}
|
}
|
||||||
rule := flowcontrol.PolicyRulesWithSubjects{subjects, resourceRules, nonResourceRules}
|
rule := flowcontrol.PolicyRulesWithSubjects{Subjects: subjects, ResourceRules: resourceRules, NonResourceRules: nonResourceRules}
|
||||||
if testDebugLogs {
|
if testDebugLogs {
|
||||||
t.Logf("For pfx=%s, mayMatchClusterScope=%v, someMatchesAllResourceRequests=%v, someMatchesAllNonResourceRequests=%v, marr=%v, manrr=%v: generated prws=%s, mu=%s, su=%s, mrr=%s, mnr=%s, srr=%s, snr=%s", pfx, mayMatchClusterScope, someMatchesAllResourceRequests, someMatchesAllNonResourceRequests, matchAllResourceRequests, matchAllNonResourceRequests, fcfmt.Fmt(rule), fcfmt.Fmt(matchingUIs), fcfmt.Fmt(skippingUIs), fcfmt.Fmt(matchingRRIs), fcfmt.Fmt(matchingNRIs), fcfmt.Fmt(skippingRRIs), fcfmt.Fmt(skippingNRIs))
|
t.Logf("For pfx=%s, mayMatchClusterScope=%v, someMatchesAllResourceRequests=%v, someMatchesAllNonResourceRequests=%v, marr=%v, manrr=%v: generated prws=%s, mu=%s, su=%s, mrr=%s, mnr=%s, srr=%s, snr=%s", pfx, mayMatchClusterScope, someMatchesAllResourceRequests, someMatchesAllNonResourceRequests, matchAllResourceRequests, matchAllNonResourceRequests, fcfmt.Fmt(rule), fcfmt.Fmt(matchingUIs), fcfmt.Fmt(skippingUIs), fcfmt.Fmt(matchingRRIs), fcfmt.Fmt(matchingNRIs), fcfmt.Fmt(skippingRRIs), fcfmt.Fmt(skippingNRIs))
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ func genUser(rng *rand.Rand, pfx string) (*flowcontrol.UserSubject, []user.Info,
|
||||||
UID: mui.UID,
|
UID: mui.UID,
|
||||||
Groups: mui.Groups,
|
Groups: mui.Groups,
|
||||||
Extra: mui.Extra}}
|
Extra: mui.Extra}}
|
||||||
return &flowcontrol.UserSubject{mui.Name}, []user.Info{mui}, skips
|
return &flowcontrol.UserSubject{Name: mui.Name}, []user.Info{mui}, skips
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupCover = []string{"system:authenticated", "system:unauthenticated"}
|
var groupCover = []string{"system:authenticated", "system:unauthenticated"}
|
||||||
|
@ -462,14 +462,14 @@ func mg(rng *rand.Rand) string {
|
||||||
func mkUserSubject(username string) flowcontrol.Subject {
|
func mkUserSubject(username string) flowcontrol.Subject {
|
||||||
return flowcontrol.Subject{
|
return flowcontrol.Subject{
|
||||||
Kind: flowcontrol.SubjectKindUser,
|
Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{username},
|
User: &flowcontrol.UserSubject{Name: username},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mkGroupSubject(group string) flowcontrol.Subject {
|
func mkGroupSubject(group string) flowcontrol.Subject {
|
||||||
return flowcontrol.Subject{
|
return flowcontrol.Subject{
|
||||||
Kind: flowcontrol.SubjectKindGroup,
|
Kind: flowcontrol.SubjectKindGroup,
|
||||||
Group: &flowcontrol.GroupSubject{group},
|
Group: &flowcontrol.GroupSubject{Name: group},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ func genGroup(rng *rand.Rand, pfx string) (*flowcontrol.GroupSubject, []user.Inf
|
||||||
if rng.Intn(2) == 0 {
|
if rng.Intn(2) == 0 {
|
||||||
skipper.Groups = append(skipper.Groups, pfx+"-k")
|
skipper.Groups = append(skipper.Groups, pfx+"-k")
|
||||||
}
|
}
|
||||||
return &flowcontrol.GroupSubject{name}, []user.Info{ui}, []user.Info{skipper}
|
return &flowcontrol.GroupSubject{Name: name}, []user.Info{ui}, []user.Info{skipper}
|
||||||
}
|
}
|
||||||
|
|
||||||
func genServiceAccount(rng *rand.Rand, pfx string) (*flowcontrol.ServiceAccountSubject, []user.Info, []user.Info) {
|
func genServiceAccount(rng *rand.Rand, pfx string) (*flowcontrol.ServiceAccountSubject, []user.Info, []user.Info) {
|
||||||
|
|
|
@ -128,56 +128,56 @@ func TestLiterals(t *testing.T) {
|
||||||
}
|
}
|
||||||
checkRules(t, true, reqRN, []flowcontrol.PolicyRulesWithSubjects{{
|
checkRules(t, true, reqRN, []flowcontrol.PolicyRulesWithSubjects{{
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindGroup,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindGroup,
|
||||||
Group: &flowcontrol.GroupSubject{"goodg1"}}},
|
Group: &flowcontrol.GroupSubject{Name: "goodg1"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"*"}}},
|
User: &flowcontrol.UserSubject{Name: "*"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindGroup,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindGroup,
|
||||||
Group: &flowcontrol.GroupSubject{"*"}}},
|
Group: &flowcontrol.GroupSubject{Name: "*"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"*"},
|
Verbs: []string{"*"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"*"},
|
APIGroups: []string{"*"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"*"},
|
Resources: []string{"*"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
|
@ -186,42 +186,42 @@ func TestLiterals(t *testing.T) {
|
||||||
})
|
})
|
||||||
checkRules(t, false, reqRN, []flowcontrol.PolicyRulesWithSubjects{{
|
checkRules(t, false, reqRN, []flowcontrol.PolicyRulesWithSubjects{{
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"badu"}}},
|
User: &flowcontrol.UserSubject{Name: "badu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindGroup,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindGroup,
|
||||||
Group: &flowcontrol.GroupSubject{"badg"}}},
|
Group: &flowcontrol.GroupSubject{Name: "badg"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"badverb"},
|
Verbs: []string{"badverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"badapig"},
|
APIGroups: []string{"badapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"badrscs"},
|
Resources: []string{"badrscs"},
|
||||||
Namespaces: []string{"goodns"}}}}, {
|
Namespaces: []string{"goodns"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
|
@ -230,28 +230,28 @@ func TestLiterals(t *testing.T) {
|
||||||
})
|
})
|
||||||
checkRules(t, true, reqRU, []flowcontrol.PolicyRulesWithSubjects{{
|
checkRules(t, true, reqRU, []flowcontrol.PolicyRulesWithSubjects{{
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
ClusterScope: true}}}, {
|
ClusterScope: true}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"*"},
|
Verbs: []string{"*"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
ClusterScope: true}}}, {
|
ClusterScope: true}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"*"},
|
APIGroups: []string{"*"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
ClusterScope: true}}}, {
|
ClusterScope: true}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
|
@ -259,28 +259,28 @@ func TestLiterals(t *testing.T) {
|
||||||
ClusterScope: true}}}})
|
ClusterScope: true}}}})
|
||||||
checkRules(t, false, reqRU, []flowcontrol.PolicyRulesWithSubjects{{
|
checkRules(t, false, reqRU, []flowcontrol.PolicyRulesWithSubjects{{
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"badverb"},
|
Verbs: []string{"badverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
ClusterScope: true}}}, {
|
ClusterScope: true}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"badapig"},
|
APIGroups: []string{"badapig"},
|
||||||
Resources: []string{"goodrscs"},
|
Resources: []string{"goodrscs"},
|
||||||
ClusterScope: true}}}, {
|
ClusterScope: true}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
Resources: []string{"badrscs"},
|
Resources: []string{"badrscs"},
|
||||||
ClusterScope: true}}}, {
|
ClusterScope: true}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
ResourceRules: []flowcontrol.ResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
APIGroups: []string{"goodapig"},
|
APIGroups: []string{"goodapig"},
|
||||||
|
@ -289,29 +289,29 @@ func TestLiterals(t *testing.T) {
|
||||||
})
|
})
|
||||||
checkRules(t, true, reqN, []flowcontrol.PolicyRulesWithSubjects{{
|
checkRules(t, true, reqN, []flowcontrol.PolicyRulesWithSubjects{{
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
NonResourceURLs: []string{"/openapi/v2"}}}}, {
|
NonResourceURLs: []string{"/openapi/v2"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
||||||
Verbs: []string{"*"},
|
Verbs: []string{"*"},
|
||||||
NonResourceURLs: []string{"/openapi/v2"}}}}, {
|
NonResourceURLs: []string{"/openapi/v2"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
NonResourceURLs: []string{"*"}}}},
|
NonResourceURLs: []string{"*"}}}},
|
||||||
})
|
})
|
||||||
checkRules(t, false, reqN, []flowcontrol.PolicyRulesWithSubjects{{
|
checkRules(t, false, reqN, []flowcontrol.PolicyRulesWithSubjects{{
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
||||||
Verbs: []string{"badverb"},
|
Verbs: []string{"badverb"},
|
||||||
NonResourceURLs: []string{"/openapi/v2"}}}}, {
|
NonResourceURLs: []string{"/openapi/v2"}}}}, {
|
||||||
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
Subjects: []flowcontrol.Subject{{Kind: flowcontrol.SubjectKindUser,
|
||||||
User: &flowcontrol.UserSubject{"goodu"}}},
|
User: &flowcontrol.UserSubject{Name: "goodu"}}},
|
||||||
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
NonResourceRules: []flowcontrol.NonResourcePolicyRule{{
|
||||||
Verbs: []string{"goodverb"},
|
Verbs: []string{"goodverb"},
|
||||||
NonResourceURLs: []string{"/closedapi/v2"}}}},
|
NonResourceURLs: []string{"/closedapi/v2"}}}},
|
||||||
|
|
|
@ -70,6 +70,7 @@ func NewTimingRatioHistogram(opts *TimingRatioHistogramOpts) *TimingRatioHistogr
|
||||||
|
|
||||||
// NewTestableTimingHistogram adds injection of the clock
|
// NewTestableTimingHistogram adds injection of the clock
|
||||||
func NewTestableTimingRatioHistogram(nowFunc func() time.Time, opts *TimingRatioHistogramOpts) *TimingRatioHistogram {
|
func NewTestableTimingRatioHistogram(nowFunc func() time.Time, opts *TimingRatioHistogramOpts) *TimingRatioHistogram {
|
||||||
|
//nolint:govet // copylocks: assignment copies lock value to ratioedOpts: k8s.io/component-base/metrics.TimingHistogramOpts contains sync.Once contains sync.Mutex
|
||||||
ratioedOpts := opts.TimingHistogramOpts
|
ratioedOpts := opts.TimingHistogramOpts
|
||||||
ratioedOpts.InitialValue /= opts.InitialDenominator
|
ratioedOpts.InitialValue /= opts.InitialDenominator
|
||||||
th := compbasemetrics.NewTestableTimingHistogram(nowFunc, &ratioedOpts)
|
th := compbasemetrics.NewTestableTimingHistogram(nowFunc, &ratioedOpts)
|
||||||
|
|
|
@ -59,7 +59,8 @@ func TestRawConn(t *testing.T) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
data, err := ioutil.ReadAll(conn.channels[0])
|
data, err := ioutil.ReadAll(conn.channels[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(data, []byte("client")) {
|
if !reflect.DeepEqual(data, []byte("client")) {
|
||||||
t.Errorf("unexpected server read: %v", data)
|
t.Errorf("unexpected server read: %v", data)
|
||||||
|
@ -75,7 +76,7 @@ func TestRawConn(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if n, err := conn.channels[1].Write([]byte("server")); err != nil && n != 6 {
|
if n, err := conn.channels[1].Write([]byte("server")); err != nil && n != 6 {
|
||||||
t.Fatalf("%d: %v", n, err)
|
t.Errorf("%d: %v", n, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -141,7 +142,8 @@ func TestBase64Conn(t *testing.T) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
data, err := ioutil.ReadAll(conn.channels[0])
|
data, err := ioutil.ReadAll(conn.channels[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(data, []byte("client")) {
|
if !reflect.DeepEqual(data, []byte("client")) {
|
||||||
t.Errorf("unexpected server read: %s", string(data))
|
t.Errorf("unexpected server read: %s", string(data))
|
||||||
|
@ -157,7 +159,7 @@ func TestBase64Conn(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if n, err := conn.channels[1].Write([]byte("server")); err != nil && n != 6 {
|
if n, err := conn.channels[1].Write([]byte("server")); err != nil && n != 6 {
|
||||||
t.Fatalf("%d: %v", n, err)
|
t.Errorf("%d: %v", n, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue