-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect Topology when assigning floating ips or not
- Loading branch information
Ole Markus With
committed
Aug 8, 2020
1 parent
6ae2bf8
commit 6ea564b
Showing
6 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package validation | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
"k8s.io/kops/pkg/apis/kops" | ||
) | ||
|
||
func openstackValidateCluster(c *kops.Cluster) (errList field.ErrorList) { | ||
if c.Spec.CloudConfig.Openstack.Router == nil || c.Spec.CloudConfig.Openstack.Router.ExternalNetwork == nil { | ||
topology := c.Spec.Topology | ||
if topology == nil || topology.Nodes == kops.TopologyPublic { | ||
errList = append(errList, field.Forbidden(field.NewPath("spec", "topology", "nodes"), "Public topology requires an external network")) | ||
} | ||
if topology == nil || topology.Masters == kops.TopologyPublic { | ||
errList = append(errList, field.Forbidden(field.NewPath("spec", "topology", "masters"), "Public topology requires an external network")) | ||
} | ||
} | ||
return errList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/kops/upup/pkg/fi" | ||
|
||
"k8s.io/kops/pkg/apis/kops" | ||
) | ||
|
||
func Test_ValidateTopology(t *testing.T) { | ||
grid := []struct { | ||
Input kops.ClusterSpec | ||
ExpectedErrors []string | ||
}{ | ||
{ | ||
Input: kops.ClusterSpec{ | ||
CloudConfig: &kops.CloudConfiguration{ | ||
Openstack: &kops.OpenstackConfiguration{}, | ||
}, | ||
}, | ||
ExpectedErrors: []string{ | ||
"Forbidden::spec.topology.nodes", | ||
"Forbidden::spec.topology.masters", | ||
}, | ||
}, | ||
{ | ||
Input: kops.ClusterSpec{ | ||
CloudConfig: &kops.CloudConfiguration{ | ||
Openstack: &kops.OpenstackConfiguration{ | ||
Router: &kops.OpenstackRouter{}, | ||
}, | ||
}, | ||
}, | ||
ExpectedErrors: []string{ | ||
"Forbidden::spec.topology.nodes", | ||
"Forbidden::spec.topology.masters", | ||
}, | ||
}, | ||
{ | ||
|
||
Input: kops.ClusterSpec{ | ||
CloudConfig: &kops.CloudConfiguration{ | ||
Openstack: &kops.OpenstackConfiguration{}, | ||
}, | ||
Topology: &kops.TopologySpec{ | ||
Masters: kops.TopologyPrivate, | ||
Nodes: kops.TopologyPrivate, | ||
}, | ||
}, | ||
ExpectedErrors: []string{}, | ||
}, | ||
{ | ||
Input: kops.ClusterSpec{ | ||
CloudConfig: &kops.CloudConfiguration{ | ||
Openstack: &kops.OpenstackConfiguration{ | ||
Router: &kops.OpenstackRouter{ | ||
ExternalNetwork: fi.String("foo"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
ExpectedErrors: []string{}, | ||
}, | ||
} | ||
|
||
for _, g := range grid { | ||
cluster := &kops.Cluster{ | ||
Spec: g.Input, | ||
} | ||
errs := openstackValidateCluster(cluster) | ||
testErrors(t, g.Input, errs, g.ExpectedErrors) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters