Skip to content

Commit ba1d1c7

Browse files
author
OpenShift Bot
authored
Merge pull request #13124 from enj/enj/i/sdn_name_func/12697,12959
Merged by openshift-bot
2 parents 517824a + 1d263a2 commit ba1d1c7

File tree

9 files changed

+21
-30
lines changed

9 files changed

+21
-30
lines changed

Diff for: api/protobuf-spec/github_com_openshift_origin_pkg_sdn_api_v1.proto

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: api/swagger-spec/oapi-v1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26657,7 +26657,7 @@
2665726657
},
2665826658
"host": {
2665926659
"type": "string",
26660-
"description": "Host is the name of the node. (This is redundant with the object's name, and this field is not actually used any more.)"
26660+
"description": "Host is the name of the node. (This is the same as the object's name, but both fields must be set.)"
2666126661
},
2666226662
"hostIP": {
2666326663
"type": "string",

Diff for: api/swagger-spec/openshift-openapi-spec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50864,7 +50864,7 @@
5086450864
"type": "string"
5086550865
},
5086650866
"host": {
50867-
"description": "Host is the name of the node. (This is redundant with the object's name, and this field is not actually used any more.)",
50867+
"description": "Host is the name of the node. (This is the same as the object's name, but both fields must be set.)",
5086850868
"type": "string"
5086950869
},
5087050870
"hostIP": {

Diff for: pkg/openapi/zz_generated.openapi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13228,7 +13228,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
1322813228
},
1322913229
"host": {
1323013230
SchemaProps: spec.SchemaProps{
13231-
Description: "Host is the name of the node. (This is redundant with the object's name, and this field is not actually used any more.)",
13231+
Description: "Host is the name of the node. (This is the same as the object's name, but both fields must be set.)",
1323213232
Type: []string{"string"},
1323313233
Format: "",
1323413234
},

Diff for: pkg/sdn/api/v1/generated.proto

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/sdn/api/v1/swagger_doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (EgressNetworkPolicySpec) SwaggerDoc() map[string]string {
7979
var map_HostSubnet = map[string]string{
8080
"": "HostSubnet describes the container subnet network on a node. The HostSubnet object must have the same name as the Node object it corresponds to.",
8181
"metadata": "Standard object's metadata.",
82-
"host": "Host is the name of the node. (This is redundant with the object's name, and this field is not actually used any more.)",
82+
"host": "Host is the name of the node. (This is the same as the object's name, but both fields must be set.)",
8383
"hostIP": "HostIP is the IP address to be used as a VTEP by other nodes in the overlay network",
8484
"subnet": "Subnet is the CIDR range of the overlay network assigned to the node for its pods",
8585
}

Diff for: pkg/sdn/api/v1/types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ type HostSubnet struct {
4545
// Standard object's metadata.
4646
kapi.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
4747

48-
// Host is the name of the node. (This is redundant with the object's name, and this
49-
// field is not actually used any more.)
48+
// Host is the name of the node. (This is the same as the object's name, but both fields must be set.)
5049
Host string `json:"host" protobuf:"bytes,2,opt,name=host"`
5150
// HostIP is the IP address to be used as a VTEP by other nodes in the overlay network
5251
HostIP string `json:"hostIP" protobuf:"bytes,3,opt,name=hostIP"`

Diff for: pkg/sdn/api/validation/validation.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package validation
22

33
import (
4+
"fmt"
45
"net"
56

67
"k8s.io/kubernetes/pkg/api/validation"
@@ -85,6 +86,10 @@ func ValidateClusterNetworkUpdate(obj *sdnapi.ClusterNetwork, old *sdnapi.Cluste
8586
func ValidateHostSubnet(hs *sdnapi.HostSubnet) field.ErrorList {
8687
allErrs := validation.ValidateObjectMeta(&hs.ObjectMeta, false, path.ValidatePathSegmentName, field.NewPath("metadata"))
8788

89+
if hs.Host != hs.Name {
90+
allErrs = append(allErrs, field.Invalid(field.NewPath("host"), hs.Host, fmt.Sprintf("must be the same as metadata.name: %q", hs.Name)))
91+
}
92+
8893
if hs.Subnet == "" {
8994
// check if annotation exists, then let the Subnet field be empty
9095
if _, ok := hs.Annotations[sdnapi.AssignHostSubnetAnnotation]; !ok {
@@ -117,8 +122,12 @@ func ValidateHostSubnetUpdate(obj *sdnapi.HostSubnet, old *sdnapi.HostSubnet) fi
117122
func ValidateNetNamespace(netnamespace *sdnapi.NetNamespace) field.ErrorList {
118123
allErrs := validation.ValidateObjectMeta(&netnamespace.ObjectMeta, false, path.ValidatePathSegmentName, field.NewPath("metadata"))
119124

125+
if netnamespace.NetName != netnamespace.Name {
126+
allErrs = append(allErrs, field.Invalid(field.NewPath("netname"), netnamespace.NetName, fmt.Sprintf("must be the same as metadata.name: %q", netnamespace.Name)))
127+
}
128+
120129
if err := sdnapi.ValidVNID(netnamespace.NetID); err != nil {
121-
allErrs = append(allErrs, field.Invalid(field.NewPath("netID"), netnamespace.NetID, err.Error()))
130+
allErrs = append(allErrs, field.Invalid(field.NewPath("netid"), netnamespace.NetID, err.Error()))
122131
}
123132
return allErrs
124133
}

Diff for: test/integration/etcd_storage_path_test.go

+4-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
kapi "k8s.io/kubernetes/pkg/api"
14-
kubeerr "k8s.io/kubernetes/pkg/api/errors"
1514
"k8s.io/kubernetes/pkg/api/meta"
1615
"k8s.io/kubernetes/pkg/api/unversioned"
1716
"k8s.io/kubernetes/pkg/client/restclient"
@@ -154,12 +153,12 @@ var etcdStorageData = map[unversioned.GroupVersionResource]struct {
154153
// --
155154

156155
// github.com/openshift/origin/pkg/sdn/api/v1
157-
gvr("", "v1", "netnamespaces"): { // This will fail to delete because meta.name != NetName but it is keyed off NetName
158-
stub: `{"metadata": {"name": "nn1"}, "netid": 100, "netname": "networkname"}`,
156+
gvr("", "v1", "netnamespaces"): {
157+
stub: `{"metadata": {"name": "networkname"}, "netid": 100, "netname": "networkname"}`,
159158
expectedEtcdPath: "openshift.io/registry/sdnnetnamespaces/networkname",
160159
},
161-
gvr("", "v1", "hostsubnets"): { // This will fail to delete because meta.name != Host but it is keyed off Host
162-
stub: `{"host": "hostname", "hostIP": "192.168.1.1", "metadata": {"name": "hs1"}, "subnet": "192.168.1.1/24"}`,
160+
gvr("", "v1", "hostsubnets"): {
161+
stub: `{"host": "hostname", "hostIP": "192.168.1.1", "metadata": {"name": "hostname"}, "subnet": "192.168.1.1/24"}`,
163162
expectedEtcdPath: "openshift.io/registry/sdnsubnets/hostname",
164163
},
165164
gvr("", "v1", "clusternetworks"): {
@@ -836,12 +835,7 @@ func (c *allClient) cleanup(all *[]cleanupData) error {
836835
mapping := (*all)[i].mapping
837836

838837
if err := c.destroy(obj, mapping); err != nil {
839-
if kubeerr.IsNotFound(err) && isInInvalidNameWhiteList(mapping) {
840-
continue
841-
}
842838
return err
843-
} else if err == nil && isInInvalidNameWhiteList(mapping) {
844-
return fmt.Errorf("Object %#v with mapping %#v should fail to delete if it is in the invalid name whitelist", obj, mapping)
845839
}
846840
}
847841
return nil
@@ -939,15 +933,6 @@ func createSerializers(config restclient.ContentConfig) (*restclient.Serializers
939933
return s, nil
940934
}
941935

942-
// do NOT add anything to this - doing so means you wrote something that is broken
943-
func isInInvalidNameWhiteList(mapping *meta.RESTMapping) bool {
944-
switch mapping.GroupVersionKind.GroupVersion().WithResource(mapping.Resource) {
945-
case gvr("", "v1", "netnamespaces"), gvr("", "v1", "hostsubnets"): // TODO figure out how to not whitelist these
946-
return true
947-
}
948-
return false
949-
}
950-
951936
func getFromEtcd(keys etcd.KeysAPI, path string) (*metaObject, error) {
952937
response, err := keys.Get(context.Background(), path, nil)
953938
if err != nil {

0 commit comments

Comments
 (0)