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

     1  package vsphere
     2  
     3  import (
     4  	"fmt"
     5  
     6  	corev1 "k8s.io/api/core/v1"
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  	capv "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
     9  
    10  	"github.com/openshift/installer/pkg/asset"
    11  	"github.com/openshift/installer/pkg/asset/installconfig"
    12  	"github.com/openshift/installer/pkg/asset/manifests/capiutils"
    13  )
    14  
    15  // GenerateClusterAssets generates the manifests for the cluster-api.
    16  func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID *installconfig.ClusterID) (*capiutils.GenerateClusterAssetsOutput, error) {
    17  	manifests := []*asset.RuntimeFile{}
    18  
    19  	assetOutput := &capiutils.GenerateClusterAssetsOutput{}
    20  
    21  	for index, vcenter := range installConfig.Config.VSphere.VCenters {
    22  		vsphereCreds := &corev1.Secret{
    23  			ObjectMeta: metav1.ObjectMeta{
    24  				Name:      fmt.Sprintf("vsphere-creds-%d", index),
    25  				Namespace: capiutils.Namespace,
    26  			},
    27  			Data: make(map[string][]byte),
    28  		}
    29  		vsphereCreds.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Secret"))
    30  
    31  		vsphereCreds.Data["username"] = []byte(vcenter.Username)
    32  		vsphereCreds.Data["password"] = []byte(vcenter.Password)
    33  
    34  		manifests = append(manifests, &asset.RuntimeFile{
    35  			Object: vsphereCreds,
    36  			File:   asset.File{Filename: fmt.Sprintf("01_%v.yaml", vsphereCreds.Name)},
    37  		})
    38  
    39  		vsphereCluster := &capv.VSphereCluster{
    40  			ObjectMeta: metav1.ObjectMeta{
    41  				Name:      fmt.Sprintf("%v-%d", clusterID.InfraID, index),
    42  				Namespace: capiutils.Namespace,
    43  			},
    44  			Spec: capv.VSphereClusterSpec{
    45  				Server: fmt.Sprintf("https://%s", vcenter.Server),
    46  				ControlPlaneEndpoint: capv.APIEndpoint{
    47  					Host: fmt.Sprintf("api.%s.%s", installConfig.Config.ObjectMeta.Name, installConfig.Config.BaseDomain),
    48  					Port: 6443,
    49  				},
    50  				IdentityRef: &capv.VSphereIdentityReference{
    51  					Kind: capv.SecretKind,
    52  					Name: vsphereCreds.Name,
    53  				},
    54  			},
    55  		}
    56  		vsphereCluster.SetGroupVersionKind(capv.GroupVersion.WithKind("VSphereCluster"))
    57  		manifests = append(manifests, &asset.RuntimeFile{
    58  			Object: vsphereCluster,
    59  			File:   asset.File{Filename: fmt.Sprintf("01_vsphere-cluster-%d.yaml", index)},
    60  		})
    61  
    62  		infra := &corev1.ObjectReference{
    63  			APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
    64  			Kind:       "VSphereCluster",
    65  			Name:       vsphereCluster.Name,
    66  			Namespace:  capiutils.Namespace,
    67  		}
    68  
    69  		assetOutput.InfrastructureRefs = append(assetOutput.InfrastructureRefs, infra)
    70  	}
    71  
    72  	assetOutput.Manifests = manifests
    73  
    74  	return assetOutput, nil
    75  }