Skip to content

Commit

Permalink
Stricter type validation for Nameserver
Browse files Browse the repository at this point in the history
Instead of string - define a Nameserver type without any fields.

Signed-off-by: Oz Tiram <[email protected]>
  • Loading branch information
oz123 committed Feb 15, 2024
1 parent 26a1e6d commit 48acfdc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/v1alpha1/maasvalidator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ type MaasInstance struct {
Auth Auth `json:"auth" yaml:"auth"`
}

type Nameserver string

type MaasInstanceRules struct {
// Unique rule name
Name string `json:"name" yaml:"name"`
// OSImages is a list of bootable os images
OSImages []OSImage `json:"bootable-images,omitempty" yaml:"bootable-images,omitempty"`
// List of DNS Servers (IP addresses)
Nameservers []string `json:"nameservers,omitempty" yaml:"nameservers,omitempty"`
Nameservers []Nameserver `json:"nameservers,omitempty" yaml:"nameservers,omitempty"`
}

type OSImage struct {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion internal/validators/maas_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (m *MaaSAPI) ListDNSServers() ([]v1alpha1.Nameserver, error) {
nameserversString := strings.Split(string(nameservers), " ")
nameservsersMaas := make([]v1alpha1.Nameserver, len(nameserversString))
for i, ns := range nameserversString {
nameservsersMaas[i] = v1alpha1.Nameserver{IPAddress: ns}
nameservsersMaas[i] = v1alpha1.Nameserver(ns)
}
return nameservsersMaas, nil
}
Expand Down

0 comments on commit 48acfdc

Please sign in to comment.