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

fix: check attr is nil prior going copy #74

Merged
merged 1 commit into from
Sep 1, 2023
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 go/manifest/v2beta2/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (g *Group) Validate(helper *validateManifestGroupsHelper) error {
func (g *Group) checkAgainstGSpec(gspec *groupSpec) error {
for _, svc := range g.Services {
if err := svc.checkAgainstGSpec(gspec); err != nil {
return fmt.Errorf("%s: group %q: %w", ErrManifestCrossValidation, g.Name, err)
return fmt.Errorf("%w: group %q: %w", ErrManifestCrossValidation, g.Name, err)
}
}

Expand Down
2 changes: 2 additions & 0 deletions go/manifest/v2beta2/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (groups Groups) Validate() error {
}

func (groups Groups) CheckAgainstGSpecs(gspecs dtypes.GroupSpecs) error {
gspecs = gspecs.Dup()

if err := groups.Validate(); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions go/manifest/v2beta2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (s *Service) checkAgainstGSpec(gspec *groupSpec) error {
for idx := range gspec.gs.Resources {
if s.Resources.ID == gspec.gs.Resources[idx].ID {
gRes = &gspec.gs.Resources[idx]
break
}
}

Expand Down
20 changes: 20 additions & 0 deletions go/node/deployment/v1beta3/groupspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ var _ ResourceGroup = (*GroupSpec)(nil)

type GroupSpecs []*GroupSpec

func (gspecs GroupSpecs) Dup() GroupSpecs {
res := make(GroupSpecs, 0, len(gspecs))

for _, gspec := range gspecs {
gs := gspec.Dup()
res = append(res, &gs)
}
return res
}

func (g GroupSpec) Dup() GroupSpec {
res := GroupSpec{
Name: g.Name,
Requirements: g.Requirements.Dup(),
Resources: g.Resources,
}

return res
}

// ValidateBasic asserts non-zero values
func (g GroupSpec) ValidateBasic() error {
return g.validate()
Expand Down
8 changes: 8 additions & 0 deletions go/node/deployment/v1beta3/resourceunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
return sdk.NewDecCoinFromDec(r.Price.Denom, r.Price.Amount.MulInt64(int64(r.Count)))
}

func (r *ResourceUnit) Dup() ResourceUnit {
return ResourceUnit{
Resources: r.Resources.Dup(),
Count: r.Count,
Price: r.GetPrice(),
}

Check warning on line 21 in go/node/deployment/v1beta3/resourceunit.go

View check run for this annotation

Codecov / codecov/patch

go/node/deployment/v1beta3/resourceunit.go#L16-L21

Added lines #L16 - L21 were not covered by tests
}

func (r *ResourceUnit) validate() error {
if r.Count > uint32(validationConfig.MaxUnitCount) || r.Count < uint32(validationConfig.MinUnitCount) {
return fmt.Errorf("error: invalid unit count (%v > %v > %v fails)",
Expand Down
10 changes: 10 additions & 0 deletions go/node/deployment/v1beta3/resourceunits.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
return s[i].ID < s[j].ID
}

func (s ResourceUnits) Dup() ResourceUnits {
res := make(ResourceUnits, 0, len(s))

for _, ru := range s {
res = append(res, ru.Dup())
}

Check warning on line 31 in go/node/deployment/v1beta3/resourceunits.go

View check run for this annotation

Codecov / codecov/patch

go/node/deployment/v1beta3/resourceunits.go#L26-L31

Added lines #L26 - L31 were not covered by tests

return s

Check warning on line 33 in go/node/deployment/v1beta3/resourceunits.go

View check run for this annotation

Codecov / codecov/patch

go/node/deployment/v1beta3/resourceunits.go#L33

Added line #L33 was not covered by tests
}

func (s ResourceUnits) Validate() error {
if count := len(s); count > validationConfig.MaxGroupUnits {
return fmt.Errorf("too many units (%v > %v)", count, validationConfig.MaxGroupUnits)
Expand Down
11 changes: 11 additions & 0 deletions go/node/types/v1beta3/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func (val attributeValue) AsString() (string, bool) {
return val.value, true
}

func (m PlacementRequirements) Dup() PlacementRequirements {
return PlacementRequirements{
SignedBy: m.SignedBy,
Attributes: m.Attributes.Dup(),
}
}

func NewStringAttribute(key, val string) Attribute {
return Attribute{
Key: key,
Expand Down Expand Up @@ -141,6 +148,10 @@ func (attr Attributes) ValidateWithRegex(r *regexp.Regexp) error {
}

func (attr Attributes) Dup() Attributes {
if attr == nil {
return nil
}

res := make(Attributes, 0, len(attr))

for _, pair := range attr {
Expand Down