Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
fix: added capx support
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakm-ntnx committed Apr 1, 2024
1 parent 2ec54be commit 53a057f
Show file tree
Hide file tree
Showing 34 changed files with 2,922 additions and 5 deletions.
12 changes: 12 additions & 0 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type ClusterConfigSpec struct {
AWS *AWSSpec `json:"aws,omitempty"`
// +optional
Docker *DockerSpec `json:"docker,omitempty"`
// +optional
Nutanix *NutanixSpec `json:"nutanix,omitempty"`

GenericClusterConfig `json:",inline"`

Expand Down Expand Up @@ -76,6 +78,16 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
}.VariableSchema().OpenAPIV3Schema,
},
)
case s.Nutanix != nil:
maps.Copy(
clusterConfigProps.OpenAPIV3Schema.Properties,
map[string]clusterv1.JSONSchemaProps{
NutanixVariableName: NutanixSpec{}.VariableSchema().OpenAPIV3Schema,
"controlPlane": NodeConfigSpec{
Nutanix: &NutanixNodeSpec{},
}.VariableSchema().OpenAPIV3Schema,
},
)
}

return clusterConfigProps
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ const (
ClusterAutoscalerVariableName = "clusterAutoscaler"
// AWSVariableName is the AWS config patch variable name.
AWSVariableName = "aws"
// NutanixVariableName is the Nutanix config patch variable name.
NutanixVariableName = "nutanix"
)
9 changes: 9 additions & 0 deletions api/v1alpha1/node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type NodeConfigSpec struct {
AWS *AWSNodeSpec `json:"aws,omitempty"`
// +optional
Docker *DockerNodeSpec `json:"docker,omitempty"`
// +optional
Nutanix *NutanixNodeSpec `json:"nutanix,omitempty"`
}

func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
Expand All @@ -49,6 +51,13 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
"docker": DockerNodeSpec{}.VariableSchema().OpenAPIV3Schema,
},
)
case s.Nutanix != nil:
maps.Copy(
nodeConfigProps.OpenAPIV3Schema.Properties,
map[string]clusterv1.JSONSchemaProps{
"nutanix": NutanixNodeSpec{}.VariableSchema().OpenAPIV3Schema,
},
)
}

return nodeConfigProps
Expand Down
162 changes: 162 additions & 0 deletions api/v1alpha1/nutanix_clusterconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright 2024 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

type NutanixSpec struct {
PrismCentralEndpoint *NutanixPrismCentralEndpointSpec `json:"prismCentralEndpoint,omitempty"`
ControlPlaneEndpoint *NutanixControlPlaneEndpointSpec `json:"controlPlaneEndpoint,omitempty"`
FailureDomains []NutanixFailureDomain `json:"failureDomains,omitempty"`
}

func (NutanixSpec) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix cluster configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"prismCentralEndpoint": NutanixPrismCentralEndpointSpec{}.VariableSchema().OpenAPIV3Schema,
"controlPlaneEndpoint": NutanixControlPlaneEndpointSpec{}.VariableSchema().OpenAPIV3Schema,
"failureDomains": NutanixFailureDomains{}.VariableSchema().OpenAPIV3Schema,
},
},
}
}

type NutanixPrismCentralEndpointSpec struct {
Host string `json:"host"`
Port int32 `json:"port"`
Insecure bool `json:"insecure"`
AdditionalTrustBundle string `json:"additionalTrustBundle,omitempty"`
CredentialSecret string `json:"credentialSecret"`
}

func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix Prism Central endpoint configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"host": {
Description: "host ip/fqdn for Prism Central Server",
Type: "string",
},
"port": {
Description: "port for Prism Central Server",
Type: "integer",
},
"insecure": {
Description: "Prism Central Certificate checking",
Type: "boolean",
},
"additionalTrustBundle": {
Description: "Name of configMap with certificate trust bundle used for Prism Central connection",
Type: "string",
},
"credentialSecret": {
Description: "Name of a Credential information secret for the target Prism instance",
Type: "string",
},
},
},
}
}

type NutanixControlPlaneEndpointSpec struct {
Host string `json:"host,omitempty"`
Port int32 `json:"port,omitempty"`
}

func (NutanixControlPlaneEndpointSpec) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix control-plane endpoint configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"host": {
Description: "host ip/fqdn for control plane API Server",
Type: "string",
},
"port": {
Description: "port for control plane API Server",
Type: "integer",
},
},
},
}
}

type NutanixFailureDomains []NutanixFailureDomain

func (NutanixFailureDomains) VariableSchema() clusterv1.VariableSchema {
resourceSchema := NutanixFailureDomain{}.VariableSchema().OpenAPIV3Schema

return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix failure domains",
Type: "array",
Items: &resourceSchema,
},
}
}

type NutanixFailureDomain struct {
// name defines the unique name of a failure domain.
// Name is required and must be at most 64 characters in length.
// It must consist of only lower case alphanumeric characters and hyphens (-).
// It must start and end with an alphanumeric character.
// This value is arbitrary and is used to identify the failure domain within the platform.
Name string `json:"name"`

// cluster is to identify the cluster (the Prism Element under management of the Prism Central),
// in which the Machine's VM will be created. The cluster identifier (uuid or name) can be obtained
// from the Prism Central console or using the prism_central API.
Cluster NutanixResourceIdentifier `json:"cluster"`

// subnets holds a list of identifiers (one or more) of the cluster's network subnets
// for the Machine's VM to connect to. The subnet identifiers (uuid or name) can be
// obtained from the Prism Central console or using the prism_central API.
Subnets []NutanixResourceIdentifier `json:"subnets"`

// indicates if a failure domain is suited for control plane nodes
ControlPlane bool `json:"controlPlane,omitempty"`
}

func (NutanixFailureDomain) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix Failure Domain",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Description: "name of failure domain",
Type: "string",
},
"cluster": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema,
"subnets": NutanixResourceIdentifiers{}.VariableSchema().OpenAPIV3Schema,
"controlPlane": {
Description: "indicates if a failure domain is suited for control plane nodes",
Type: "boolean",
},
},
},
}
}

type NutanixResourceIdentifiers []NutanixResourceIdentifier

func (NutanixResourceIdentifiers) VariableSchema() clusterv1.VariableSchema {
resourceSchema := NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema

return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix resource identifier",
Type: "array",
Items: &resourceSchema,
},
}
}
Loading

0 comments on commit 53a057f

Please sign in to comment.