create NetworkType to suport OVNKubernetes

This commit is contained in:
Drew Anderson 2021-06-22 15:35:18 +02:00
Родитель 45771188c2
Коммит bfa19ccb80
5 изменённых файлов: 73 добавлений и 2 удалений

Просмотреть файл

@ -198,6 +198,7 @@ type NetworkProfile struct {
PodCIDR string `json:"podCidr,omitempty"`
ServiceCIDR string `json:"serviceCidr,omitempty"`
NetworkType string `json:"networkType,omitempty"`
APIServerPrivateEndpointIP string `json:"privateEndpointIp,omitempty"`
}

Просмотреть файл

@ -116,6 +116,9 @@ type ServicePrincipalProfile struct {
// NetworkProfile represents a network profile.
type NetworkProfile struct {
// The Network Provider to use when installing the cluster.
NetworkType string `json:"networkType,omitempty"`
// The CIDR used for OpenShift/Kubernetes Pods.
PodCIDR string `json:"podCidr,omitempty"`
@ -123,6 +126,12 @@ type NetworkProfile struct {
ServiceCIDR string `json:"serviceCidr,omitempty"`
}
// NetworkType constants.
const (
NetworkTypeOVNKubernetes string = "OVNKubernetes"
NetworkTypeOpenShiftSDN string = "OpenShiftSDN"
)
// MasterProfile represents a master profile.
type MasterProfile struct {
// The size of the master VMs.

Просмотреть файл

@ -37,6 +37,7 @@ func (c *openShiftClusterConverter) ToExternal(oc *api.OpenShiftCluster) interfa
NetworkProfile: NetworkProfile{
PodCIDR: oc.Properties.NetworkProfile.PodCIDR,
ServiceCIDR: oc.Properties.NetworkProfile.ServiceCIDR,
NetworkType: oc.Properties.NetworkProfile.NetworkType,
},
MasterProfile: MasterProfile{
VMSize: VMSize(oc.Properties.MasterProfile.VMSize),
@ -140,6 +141,7 @@ func (c *openShiftClusterConverter) ToInternal(_oc interface{}, out *api.OpenShi
out.Properties.ServicePrincipalProfile.ClientSecret = api.SecureString(oc.Properties.ServicePrincipalProfile.ClientSecret)
out.Properties.NetworkProfile.PodCIDR = oc.Properties.NetworkProfile.PodCIDR
out.Properties.NetworkProfile.ServiceCIDR = oc.Properties.NetworkProfile.ServiceCIDR
out.Properties.NetworkProfile.NetworkType = oc.Properties.NetworkProfile.NetworkType
out.Properties.MasterProfile.VMSize = api.VMSize(oc.Properties.MasterProfile.VMSize)
out.Properties.MasterProfile.SubnetID = oc.Properties.MasterProfile.SubnetID
out.Properties.MasterProfile.EncryptionAtHost = oc.Properties.MasterProfile.EncryptionAtHost

Просмотреть файл

@ -4,6 +4,7 @@ package v20210131preview
// Licensed under the Apache License 2.0.
import (
"fmt"
"net"
"net/http"
"net/url"
@ -90,7 +91,7 @@ func (sv *openShiftClusterStaticValidator) validateProperties(path string, p *Op
if err := sv.validateServicePrincipalProfile(path+".servicePrincipalProfile", &p.ServicePrincipalProfile); err != nil {
return err
}
if err := sv.validateNetworkProfile(path+".networkProfile", &p.NetworkProfile); err != nil {
if err := sv.validateNetworkProfile(path+".networkProfile", &p.NetworkProfile, isCreate); err != nil {
return err
}
if err := sv.validateMasterProfile(path+".masterProfile", &p.MasterProfile); err != nil {
@ -182,7 +183,7 @@ func (sv *openShiftClusterStaticValidator) validateServicePrincipalProfile(path
return nil
}
func (sv *openShiftClusterStaticValidator) validateNetworkProfile(path string, np *NetworkProfile) error {
func (sv *openShiftClusterStaticValidator) validateNetworkProfile(path string, np *NetworkProfile, isCreate bool) error {
_, pod, err := net.ParseCIDR(np.PodCIDR)
if err != nil {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".podCidr", "The provided pod CIDR '%s' is invalid: '%s'.", np.PodCIDR, err)
@ -210,6 +211,13 @@ func (sv *openShiftClusterStaticValidator) validateNetworkProfile(path string, n
}
}
if isCreate {
if np.NetworkType != NetworkTypeOVNKubernetes && np.NetworkType != NetworkTypeOpenShiftSDN {
errorMsg := fmt.Sprintf("The provided networkType must be either '%s' or '%s'.", NetworkTypeOVNKubernetes, NetworkTypeOpenShiftSDN)
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".networkType", errorMsg)
}
}
return nil
}

Просмотреть файл

@ -78,6 +78,7 @@ func validOpenShiftCluster() *OpenShiftCluster {
NetworkProfile: NetworkProfile{
PodCIDR: "10.128.0.0/14",
ServiceCIDR: "172.30.0.0/16",
NetworkType: "OVNKubernetes",
},
MasterProfile: MasterProfile{
VMSize: VMSizeStandardD8sV3,
@ -462,6 +463,56 @@ func TestOpenShiftClusterStaticValidateNetworkProfile(t *testing.T) {
runTests(t, testModeUpdate, tests)
}
func TestOpenShiftClusterStaticValidateNetworkProfileType(t *testing.T) {
createtests := []*validateTest{
{
name: "valid",
},
{
name: "networkProvider",
modify: func(oc *OpenShiftCluster) {
oc.Properties.NetworkProfile.NetworkType = "InvalidOption"
},
wantErr: "400: InvalidParameter: properties.networkProfile.networkType: The provided networkType must be either 'OVNKubernetes' or 'OpenShiftSDN'.",
},
{
name: "networkProvider",
modify: func(oc *OpenShiftCluster) {
oc.Properties.NetworkProfile.NetworkType = "OpenShiftSDN"
},
},
{
name: "networkProvider",
modify: func(oc *OpenShiftCluster) {
oc.Properties.NetworkProfile.NetworkType = "OVNKubernetes"
},
},
}
updatetests := []*validateTest{
{
name: "valid",
},
{
name: "networkProvider",
modify: func(oc *OpenShiftCluster) {
oc.Properties.NetworkProfile.NetworkType = "InvalidOption"
},
wantErr: "400: PropertyChangeNotAllowed: properties.networkProfile.networkType: Changing property 'properties.networkProfile.networkType' is not allowed.",
},
{
name: "networkProvider",
modify: func(oc *OpenShiftCluster) {
oc.Properties.NetworkProfile.NetworkType = "OpenShiftSDN"
},
wantErr: "400: PropertyChangeNotAllowed: properties.networkProfile.networkType: Changing property 'properties.networkProfile.networkType' is not allowed.",
},
}
runTests(t, testModeCreate, createtests)
runTests(t, testModeUpdate, updatetests)
}
func TestOpenShiftClusterStaticValidateMasterProfile(t *testing.T) {
commonTests := []*validateTest{
{