Skip to content

refactor: change api format to match other plugins #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 23, 2024
98 changes: 73 additions & 25 deletions api/v1alpha1/maasvalidator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,95 @@ import (

// MaasValidatorSpec defines the desired state of MaasValidator
type MaasValidatorSpec struct {
MaasInstanceRules `json:"MaasInstanceRules,omitempty" yaml:"MaasInstanceRules,omitempty"`
MaasInstance `json:"MaasInstance" yaml:"MaasInstance"`
Auth Auth `json:"auth" yaml:"auth"`
// Host is the URL for your MAAS Instance
Host string `json:"host" yaml:"host"`

ImageRules []ImageRule `json:"imageRules,omitempty" yaml:"imageRules,omitempty"`
InternalDNSRules []InternalDNSRule `json:"internalDNSRules,omitempty" yaml:"internalDNSRules,omitempty"`
UpstreamDNSRules []UpstreamDNSRule `json:"upstreamDNSRules,omitempty" yaml:"upstreamDNSRules,omitempty"`
ResourceAvailabilityRules []ResourceAvailabilityRule `json:"resourceAvailabilityRules,omitempty" yaml:"resourceAvailabilityRules,omitempty"`
}

// ResultCount returns the number of validation results expected for an MaasValidatorSpec.
func (s MaasValidatorSpec) ResultCount() int {
return len(s.MaasInstanceRules.OSImages)
return len(s.ImageRules) + len(s.InternalDNSRules) + len(s.UpstreamDNSRules) + len(s.ResourceAvailabilityRules)
}

// MaasInstance describes the MaaS host
type MaasInstance struct {
// Host is the URL for your MaaS instance
Host string `json:"host" yaml:"host"`
Auth Auth `json:"auth" yaml:"auth"`
// Auth provides authentication information for the MAAS Instance
type Auth struct {
SecretName string `json:"secretName" yaml:"secretName"`
TokenKey string `json:"token" yaml:"token"`
}

// MaasInstanceRules defines the rules for the MaaS instance
type MaasInstanceRules struct {
// Unique rule name
// ImageRule defines a rule for validating one or more OS images
type ImageRule struct {
// Unique name for the rule
Name string `json:"name" yaml:"name"`
// OSImages is a list of bootable os images
OSImages []OSImage `json:"bootable-images,omitempty" yaml:"bootable-images,omitempty"`

// Auth provides authentication information for the MaaS Instance
Auth Auth `json:"auth" yaml:"auth"`
// The list of OS images to validate
Images []Image `json:"images" yaml:"images"`
}

// OSImage defines an OS Image
type OSImage struct {
// Image defines one OS image
type Image struct {
// The name of the bootable image
Name string `json:"name" yaml:"name"`
// OS Architecture
Architecture string `json:"os-arch" yaml:"os-arch"`
Architecture string `json:"architecture" yaml:"architecture"`
}

// Auth provides authentication information for the MaaS Instance
type Auth struct {
// +kubebuilder:validation:Optional
SecretName string `json:"secretName" yaml:"secretName"`
// +kubebuilder:validation:Optional
TokenKey string `json:"token" yaml:"token"`
// InternalDNSRule provides rules for the internal DNS server
type InternalDNSRule struct {
// The domain name for the internal DNS server
MaasDomain string `json:"maasDomain" yaml:"maasDomain"`
// The DNS records for the internal DNS server
DNSRecords []DNSRecord `json:"dnsRecords" yaml:"dnsRecords"`
}

// DNSRecord provides an internal DNS record
type DNSRecord struct {
// The hostname for the DNS record
Hostname string `json:"hostname" yaml:"hostname"`
// The IP address for the DNS record
IP string `json:"ip" yaml:"ip"`
// The type of DNS record
Type string `json:"type" yaml:"type"`
// Optional Time To Live (TTL) for the DNS record
TTL int `json:"ttl,omitempty" yaml:"ttl,omitempty"`
}

// UpstreamDNSRule provides rules for validating the external DNS server
type UpstreamDNSRule struct {
// Unique name for the rule
Name string `json:"name" yaml:"name"`
// The minimum expected number of upstream DNS servers
NumDNSServers int `json:"numDNSServers" yaml:"numDNSServers"`
}

// ResourceAvailabilityRule provides rules for validating resource availability
type ResourceAvailabilityRule struct {
// Unique name for the rule
Name string `json:"name" yaml:"name"`
// The list of resources to validate
Resources []Resource `json:"resources" yaml:"resources"`
}

// Resource defines a compute resource
type Resource struct {
// Availability Zone
AZ string `json:"az" yaml:"az"`
// Minimum desired number of machines
NumMachines int `json:"numMachines" yaml:"numMachines"`
// Minimum CPU cores per machine
NumCPU int `json:"numCPU" yaml:"numCPU"`
// Minimum RAM per machine in GB
NumRAM int `json:"numRAM" yaml:"numRAM"`
// Minimum Disk space per machine in GB
NumDisk int `json:"numDisk" yaml:"numDisk"`
// Optional machine pool
Pool string `json:"pool,omitempty" yaml:"pool,omitempty"`
// Optional machine labels
Labels []string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

// MaasValidatorStatus defines the observed state of MaasValidator
Expand Down
138 changes: 119 additions & 19 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading