This repository was archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add CAPX API #13
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cac1091
feat: add CAPX API
dkoshkin a338591
refactor: reuse existing CAPX types
dkoshkin 6427b60
fix: set allowed enums for Nutanix resource types
dkoshkin 28b17ba
fix: set required for Nutanix node type
dkoshkin a952c7a
fix: reuse resource.Quantity types
dkoshkin 870884b
fix: set defaults and validation
dkoshkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2024 D2iQ, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/utils/ptr" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
|
||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/variables" | ||
) | ||
|
||
const ( | ||
PrismCentralPort = 9440 | ||
) | ||
|
||
// NutanixSpec defines the desired state of NutanixCluster. | ||
type NutanixSpec struct { | ||
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. | ||
// host can be either DNS name or ip address | ||
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"` | ||
|
||
// Nutanix Prism Central endpoint configuration. | ||
PrismCentralEndpoint NutanixPrismCentralEndpointSpec `json:"prismCentralEndpoint"` | ||
} | ||
|
||
func (NutanixSpec) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Description: "Nutanix cluster configuration", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"controlPlaneEndpoint": ControlPlaneEndpointSpec{}.VariableSchema().OpenAPIV3Schema, | ||
"prismCentralEndpoint": NutanixPrismCentralEndpointSpec{}.VariableSchema().OpenAPIV3Schema, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type NutanixPrismCentralEndpointSpec struct { | ||
// address is the endpoint address (DNS name or IP address) of the Nutanix Prism Central | ||
Address string `json:"address"` | ||
|
||
// port is the port number to access the Nutanix Prism Central | ||
Port int32 `json:"port"` | ||
|
||
// use insecure connection to Prism Central endpoint | ||
// +optional | ||
Insecure bool `json:"insecure"` | ||
|
||
// A reference to the ConfigMap containing a PEM encoded x509 cert for the RootCA that was used to create | ||
// the certificate for a Prism Central that uses certificates that were issued by a non-publicly trusted RootCA. | ||
// The trust bundle is added to the cert pool used to authenticate the TLS connection to the Prism Central. | ||
// +optional | ||
AdditionalTrustBundle *corev1.LocalObjectReference `json:"additionalTrustBundle,omitempty"` | ||
dkoshkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// A reference to the Secret for credential information for the target Prism Central instance | ||
Credentials corev1.LocalObjectReference `json:"credentials"` | ||
dkoshkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Description: "Nutanix Prism Central endpoint configuration", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"address": { | ||
Description: "the endpoint address (DNS name or IP address) of the Nutanix Prism Central", | ||
Type: "string", | ||
MinLength: ptr.To[int64](1), | ||
}, | ||
"port": { | ||
Description: "The port number to access the Nutanix Prism Central", | ||
Type: "integer", | ||
Default: variables.MustMarshal(PrismCentralPort), | ||
Minimum: ptr.To[int64](1), | ||
Maximum: ptr.To[int64](65535), | ||
}, | ||
"insecure": { | ||
Description: "Use insecure connection to Prism Central endpoint", | ||
Type: "boolean", | ||
}, | ||
"additionalTrustBundle": { | ||
Description: "A reference to the ConfigMap containing a PEM encoded x509 cert for the RootCA " + | ||
"that was used to create the certificate for a Prism Central that uses certificates " + | ||
"that were issued by a non-publicly trusted RootCA." + | ||
"The trust bundle is added to the cert pool used to authenticate the TLS connection " + | ||
"to the Prism Central.", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"name": { | ||
Description: "The name of the ConfigMap", | ||
Type: "string", | ||
}, | ||
}, | ||
Required: []string{"name"}, | ||
}, | ||
"credentials": { | ||
Description: "A reference to the Secret for credential information" + | ||
"for the target Prism Central instance", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"name": { | ||
Description: "The name of the Secret", | ||
Type: "string", | ||
}, | ||
}, | ||
Required: []string{"name"}, | ||
}, | ||
}, | ||
Required: []string{"address", "port", "credentials"}, | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Copyright 2024 D2iQ, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
|
||
capxv1 "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/variables" | ||
) | ||
|
||
type NutanixNodeSpec struct { | ||
MachineDetails NutanixMachineDetails `json:"machineDetails"` | ||
} | ||
|
||
func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Description: "Nutanix Node configuration", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"machineDetails": NutanixMachineDetails{}.VariableSchema().OpenAPIV3Schema, | ||
}, | ||
Required: []string{"machineDetails"}, | ||
}, | ||
} | ||
} | ||
|
||
type NutanixMachineDetails struct { | ||
// vcpusPerSocket is the number of vCPUs per socket of the VM | ||
VCPUsPerSocket int32 `json:"vcpusPerSocket"` | ||
|
||
// vcpuSockets is the number of vCPU sockets of the VM | ||
VCPUSockets int32 `json:"vcpuSockets"` | ||
|
||
// memorySize is the memory size (in Quantity format) of the VM | ||
MemorySize resource.Quantity `json:"memorySize"` | ||
|
||
// image is to identify the rhcos image uploaded to the Prism Central (PC) | ||
// The image identifier (uuid or name) can be obtained from the Prism Central console | ||
// or using the prism_central API. | ||
Image NutanixResourceIdentifier `json:"image"` | ||
|
||
// 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"` | ||
|
||
// subnet is to identify the cluster's network subnet to use for the Machine's VM | ||
// The cluster identifier (uuid or name) can be obtained from the Prism Central console | ||
// or using the prism_central API. | ||
Subnets NutanixResourceIdentifiers `json:"subnet"` | ||
|
||
// Defines the boot type of the virtual machine. Only supports UEFI and Legacy | ||
BootType NutanixBootType `json:"bootType,omitempty"` | ||
|
||
// systemDiskSize is size (in Quantity format) of the system disk of the VM | ||
// The minimum systemDiskSize is 20Gi bytes | ||
SystemDiskSize resource.Quantity `json:"systemDiskSize"` | ||
} | ||
|
||
func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Description: "Nutanix Machine configuration", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"vcpusPerSocket": { | ||
Description: "vcpusPerSocket is the number of vCPUs per socket of the VM", | ||
Type: "integer", | ||
}, | ||
"vcpuSockets": { | ||
Description: "vcpuSockets is the number of vCPU sockets of the VM", | ||
Type: "integer", | ||
}, | ||
"memorySize": { | ||
Description: "memorySize is the memory size (in Quantity format) of the VM eg. 4Gi", | ||
Type: "string", | ||
}, | ||
"image": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema, | ||
"cluster": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema, | ||
"subnet": NutanixResourceIdentifiers{}.VariableSchema().OpenAPIV3Schema, | ||
"bootType": NutanixBootType(capxv1.NutanixBootTypeLegacy).VariableSchema().OpenAPIV3Schema, | ||
"systemDiskSize": { | ||
Description: "systemDiskSize is size (in Quantity format) of the system disk of the VM eg. 20Gi", | ||
Type: "string", | ||
}, | ||
}, | ||
Required: []string{"vcpusPerSocket", "vcpuSockets", "memorySize", "image", "cluster", "subnet", "systemDiskSize"}, | ||
}, | ||
} | ||
} | ||
|
||
// NutanixIdentifierType is an enumeration of different resource identifier types. | ||
type NutanixIdentifierType capxv1.NutanixIdentifierType | ||
|
||
func (NutanixIdentifierType) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Type: "string", | ||
Description: "NutanixIdentifierType is an enumeration of different resource identifier types", | ||
dkoshkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Enum: variables.MustMarshalValuesToEnumJSON( | ||
capxv1.NutanixIdentifierUUID, | ||
capxv1.NutanixIdentifierName, | ||
), | ||
}, | ||
} | ||
} | ||
|
||
// NutanixBootType is an enumeration of different boot types. | ||
type NutanixBootType capxv1.NutanixBootType | ||
|
||
func (NutanixBootType) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Type: "string", | ||
Description: "NutanixBootType is an enumeration of different boot types.", | ||
dkoshkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Enum: variables.MustMarshalValuesToEnumJSON( | ||
capxv1.NutanixBootTypeLegacy, | ||
capxv1.NutanixBootTypeUEFI, | ||
), | ||
}, | ||
} | ||
} | ||
|
||
type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier | ||
|
||
func (NutanixResourceIdentifier) VariableSchema() clusterv1.VariableSchema { | ||
return clusterv1.VariableSchema{ | ||
OpenAPIV3Schema: clusterv1.JSONSchemaProps{ | ||
Description: "Nutanix Resource Identifier", | ||
Type: "object", | ||
Properties: map[string]clusterv1.JSONSchemaProps{ | ||
"type": NutanixIdentifierType(capxv1.NutanixIdentifierName).VariableSchema().OpenAPIV3Schema, | ||
"uuid": { | ||
Type: "string", | ||
Description: "uuid is the UUID of the resource in the PC.", | ||
}, | ||
"name": { | ||
Type: "string", | ||
Description: "name is the resource name in the PC.", | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
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, | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.