github.com/openshift/installer@v1.4.17/pkg/asset/manifests/nutanix/cluster.go (about) 1 package nutanix 2 3 import ( 4 "fmt" 5 6 capnv1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1" 7 credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials" 8 corev1 "k8s.io/api/core/v1" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 "k8s.io/utils/ptr" 11 capv1 "sigs.k8s.io/cluster-api/api/v1beta1" 12 13 "github.com/openshift/installer/pkg/asset" 14 "github.com/openshift/installer/pkg/asset/installconfig" 15 "github.com/openshift/installer/pkg/asset/manifests/capiutils" 16 ) 17 18 // GenerateClusterAssets generates the manifests for the cluster-api. 19 func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID *installconfig.ClusterID) (*capiutils.GenerateClusterAssetsOutput, error) { 20 manifests := []*asset.RuntimeFile{} 21 ic := installConfig.Config 22 23 // generate the NutanixCluster manifest. 24 ntxCluster := &capnv1.NutanixCluster{ 25 ObjectMeta: metav1.ObjectMeta{ 26 Name: clusterID.InfraID, 27 Namespace: capiutils.Namespace, 28 }, 29 Spec: capnv1.NutanixClusterSpec{ 30 ControlPlaneEndpoint: capv1.APIEndpoint{ 31 Host: fmt.Sprintf("api.%s.%s", installConfig.Config.ObjectMeta.Name, installConfig.Config.BaseDomain), 32 Port: 6443, 33 }, 34 PrismCentral: &credentialTypes.NutanixPrismEndpoint{ 35 Address: ic.Platform.Nutanix.PrismCentral.Endpoint.Address, 36 Port: ic.Platform.Nutanix.PrismCentral.Endpoint.Port, 37 }, 38 FailureDomains: []capnv1.NutanixFailureDomain{}, 39 }, 40 } 41 ntxCluster.SetGroupVersionKind(capnv1.GroupVersion.WithKind("NutanixCluster")) 42 43 // generate the nutanix-credentials secret manifest. 44 // #nosec G101 45 credentialsDataFmt := `[{ 46 "type": "basic_auth", 47 "data": { 48 "prismCentral":{ 49 "username": "%s", 50 "password": "%s" 51 } 52 } 53 }]` 54 stringData := make(map[string]string, 1) 55 stringData["credentials"] = fmt.Sprintf(credentialsDataFmt, ic.Platform.Nutanix.PrismCentral.Username, ic.Platform.Nutanix.PrismCentral.Password) 56 credSecret := &corev1.Secret{ 57 ObjectMeta: metav1.ObjectMeta{ 58 Name: "nutanix-credentials", 59 Namespace: capiutils.Namespace, 60 }, 61 StringData: stringData, 62 } 63 manifests = append(manifests, &asset.RuntimeFile{ 64 Object: credSecret, 65 File: asset.File{Filename: "01_nutanix-creds.yaml"}, 66 }) 67 credSecret.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Secret")) 68 69 ntxCluster.Spec.PrismCentral.CredentialRef = &credentialTypes.NutanixCredentialReference{ 70 Kind: credentialTypes.SecretKind, 71 Name: "nutanix-credentials", 72 Namespace: capiutils.Namespace, 73 } 74 75 if ic.AdditionalTrustBundle != "" { 76 ntxCluster.Spec.PrismCentral.AdditionalTrustBundle = &credentialTypes.NutanixTrustBundleReference{ 77 Kind: credentialTypes.NutanixTrustBundleKindString, 78 Data: ic.AdditionalTrustBundle, 79 } 80 } 81 82 for _, fd := range ic.Platform.Nutanix.FailureDomains { 83 subnets := make([]capnv1.NutanixResourceIdentifier, 0, len(fd.SubnetUUIDs)) 84 for _, subnetUUID := range fd.SubnetUUIDs { 85 subnets = append(subnets, capnv1.NutanixResourceIdentifier{Type: capnv1.NutanixIdentifierUUID, UUID: ptr.To(subnetUUID)}) 86 } 87 88 ntxCluster.Spec.FailureDomains = append(ntxCluster.Spec.FailureDomains, capnv1.NutanixFailureDomain{ 89 Name: fd.Name, 90 Cluster: capnv1.NutanixResourceIdentifier{ 91 Type: capnv1.NutanixIdentifierUUID, 92 UUID: ptr.To(fd.PrismElement.UUID), 93 }, 94 Subnets: subnets, 95 }) 96 } 97 98 manifests = append(manifests, &asset.RuntimeFile{ 99 Object: ntxCluster, 100 File: asset.File{Filename: "01_nutanix-cluster.yaml"}, 101 }) 102 103 return &capiutils.GenerateClusterAssetsOutput{ 104 Manifests: manifests, 105 InfrastructureRefs: []*corev1.ObjectReference{ 106 { 107 APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", 108 Kind: "NutanixCluster", 109 Name: clusterID.InfraID, 110 Namespace: capiutils.Namespace, 111 }, 112 }, 113 }, nil 114 }