github.com/openshift/installer@v1.4.17/pkg/asset/manifests/ovnkubeconfig.go (about)

     1  package manifests
     2  
     3  import (
     4  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     5  	"sigs.k8s.io/yaml"
     6  
     7  	configv1 "github.com/openshift/api/config/v1"
     8  	operatorv1 "github.com/openshift/api/operator/v1"
     9  )
    10  
    11  // OvnKubeConfig creates a config file for the OVNKubernetes CNI provider
    12  func OvnKubeConfig(cns []configv1.ClusterNetworkEntry, sn []string, useHostRouting bool) ([]byte, error) {
    13  
    14  	operCNs := []operatorv1.ClusterNetworkEntry{}
    15  	for _, cn := range cns {
    16  		ocn := operatorv1.ClusterNetworkEntry{
    17  			CIDR:       cn.CIDR,
    18  			HostPrefix: cn.HostPrefix,
    19  		}
    20  		operCNs = append(operCNs, ocn)
    21  	}
    22  	ovnConfig := operatorv1.Network{
    23  		TypeMeta: metav1.TypeMeta{
    24  			APIVersion: "operator.openshift.io/v1",
    25  			Kind:       "Network",
    26  		},
    27  		ObjectMeta: metav1.ObjectMeta{
    28  			Name: "cluster",
    29  		},
    30  		Spec: operatorv1.NetworkSpec{
    31  			OperatorSpec:   operatorv1.OperatorSpec{ManagementState: operatorv1.Managed},
    32  			ClusterNetwork: operCNs,
    33  			ServiceNetwork: sn,
    34  			DefaultNetwork: operatorv1.DefaultNetworkDefinition{
    35  				Type: operatorv1.NetworkTypeOVNKubernetes,
    36  				OVNKubernetesConfig: &operatorv1.OVNKubernetesConfig{
    37  					GatewayConfig: &operatorv1.GatewayConfig{
    38  						RoutingViaHost: useHostRouting,
    39  					},
    40  				},
    41  			},
    42  		},
    43  		Status: operatorv1.NetworkStatus{},
    44  	}
    45  
    46  	return yaml.Marshal(ovnConfig)
    47  }