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 fe46b44 commit 6b5b01d
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)

Check warning on line 60 in internal/validators/maas_validator.go

View check run for this annotation

Codecov / codecov/patch

internal/validators/maas_validator.go#L57-L60

Added lines #L57 - L60 were not covered by tests
}
return nameservsersMaas, nil

Check warning on line 62 in internal/validators/maas_validator.go

View check run for this annotation

Codecov / codecov/patch

internal/validators/maas_validator.go#L62

Added line #L62 was not covered by tests
}
Expand Down

0 comments on commit 6b5b01d

Please sign in to comment.