Skip to content
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

refactor: update image validator to only consider "synced" images #113

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$TARGETPLATFORM golang:1.22 AS builder
FROM --platform=$TARGETPLATFORM golang:alpine3.19 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.devspace
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$TARGETPLATFORM golang:alpine3.18 as builder
FROM --platform=$TARGETPLATFORM golang:alpine3.19 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
sigs.k8s.io/controller-runtime v0.18.4
)

replace github.com/canonical/gomaasclient v0.6.0 => github.com/arturshadnik/gomaasclient v0.0.0-20240730214136-d7dd8da98797
replace github.com/canonical/gomaasclient v0.6.0 => github.com/arturshadnik/gomaasclient v0.0.0-20240731231205-8239cfb13409

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/arturshadnik/gomaasclient v0.0.0-20240730214136-d7dd8da98797 h1:lr8q69ZH1hcg8MdUSqg6s09XbgoWqRh9kyDcSxQl+gI=
github.com/arturshadnik/gomaasclient v0.0.0-20240730214136-d7dd8da98797/go.mod h1:rRYH2hfLDZ7Z6LNmNBbLzwnu1wK894fznN5pbVtur/s=
github.com/arturshadnik/gomaasclient v0.0.0-20240731231205-8239cfb13409 h1:J4cbZQZFlLZNy5nGyDyPW0/VI4bivvR0EyZiR/H9Y7k=
github.com/arturshadnik/gomaasclient v0.0.0-20240731231205-8239cfb13409/go.mod h1:rRYH2hfLDZ7Z6LNmNBbLzwnu1wK894fznN5pbVtur/s=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/maasvalidator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type MockIDNSRulesService struct {
func (b *MockBootResourcesService) Get(params *entity.BootResourcesReadParams) ([]entity.BootResource, error) {
return []entity.BootResource{
{
Type: "Synced",
Name: "Ubuntu",
Architecture: "amd64/ga-22.04",
},
Expand All @@ -63,7 +64,7 @@ func (m *MockMachinesService) Get(params *entity.MachinesParams) ([]entity.Machi
}, nil
}

func (i *MockIDNSRulesService) Get(params *entity.DNSResourcesGetParams) ([]entity.DNSResource, error) {
func (i *MockIDNSRulesService) Get(params *entity.DNSResourcesParams) ([]entity.DNSResource, error) {
return []entity.DNSResource{
{
FQDN: "foo.maas.sc",
Expand Down
8 changes: 4 additions & 4 deletions internal/validators/dns/internal_dns_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func (s *InternalDNSRulesService) ReconcileMaasInstanceInternalDNSRule(rule v1al
}

func (s *InternalDNSRulesService) ensureDNSResources(rule v1alpha1.InternalDNSRule) ([]string, []error) {
details := make([]string, 0)
errs := make([]error, 0)

maasDNSResources, err := s.api.Get(&entity.DNSResourcesGetParams{All: true})
maasDNSResources, err := s.api.Get(&entity.DNSResourcesParams{All: true})
if err != nil {
return nil, []error{err}
}

details := make([]string, 0)
errs := make([]error, 0)

formattedRecords := formatDNSRecords(maasDNSResources)

for _, res := range rule.DNSResources {
Expand Down
2 changes: 1 addition & 1 deletion internal/validators/dns/internal_dns_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type DummyDNSResources struct {
resources []entity.DNSResource
}

func (d *DummyDNSResources) Get(params *entity.DNSResourcesGetParams) ([]entity.DNSResource, error) {
func (d *DummyDNSResources) Get(params *entity.DNSResourcesParams) ([]entity.DNSResource, error) {
return d.resources, nil
}

Expand Down
7 changes: 4 additions & 3 deletions internal/validators/dns/upstream_dns_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ func (s *UpstreamDNSRulesService) ReconcileMaasInstanceUpstreamDNSRule(rule v1al
}

func (s *UpstreamDNSRulesService) findDNSServers(expected int) ([]string, []error) {
details := make([]string, 0)
errs := make([]error, 0)

ns, err := s.api.Get("upstream_dns")
if err != nil {
return nil, []error{err}
}

details := make([]string, 0)
errs := make([]error, 0)

nameservers := strings.Split(string(ns), " ")
numServers := len(nameservers)

Expand Down
22 changes: 13 additions & 9 deletions internal/validators/os/os_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,29 @@

// convertBootResourceToOSImage formats a list of BootResources as a list of OSImages
func convertBootResourceToOSImage(images []entity.BootResource) []v1alpha1.Image {
converted := make([]v1alpha1.Image, len(images))
for i, img := range images {
converted[i] = v1alpha1.Image{
Name: img.Name,
Architecture: img.Architecture,
converted := make([]v1alpha1.Image, 0)
for _, img := range images {
// the client lib does not seem to care about params it is given, so for now manually filtering
if img.Type == "Synced" {
converted = append(converted, v1alpha1.Image{
Name: img.Name,
Architecture: img.Architecture,
})
}
}
return converted
}

// findBootResources checks if a list of Images is a subset of a list of BootResources
func (s *ImageRulesService) findBootResources(rule v1alpha1.ImageRule) ([]string, []error) {
images, err := s.api.Get(&entity.BootResourcesReadParams{Type: "Synced"})
if err != nil {
return nil, []error{err}

Check warning on line 66 in internal/validators/os/os_validator.go

View check run for this annotation

Codecov / codecov/patch

internal/validators/os/os_validator.go#L66

Added line #L66 was not covered by tests
}

details := make([]string, 0)
errs := make([]error, 0)

images, err := s.api.Get(&entity.BootResourcesReadParams{})
if err != nil {
return details, errs
}
converted := convertBootResourceToOSImage(images)
convertedSet := mapset.NewSet(converted...)
imgRulesSet := mapset.NewSet(rule.Images...)
Expand Down
1 change: 1 addition & 0 deletions internal/validators/os/os_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestReconcileMaasInstanceImageRule(t *testing.T) {
&DummyBootResources{
images: []entity.BootResource{
{
Type: "Synced",
Name: "Ubuntu",
Architecture: "amd64/ga-20.04",
},
Expand Down