Skip to content

Commit

Permalink
Fix manual rollback (immediate rollback is still not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Jan 1, 2022
1 parent d418a59 commit 17d46a4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
58 changes: 29 additions & 29 deletions pkg/awstargetgroupset/awstargetgroupset.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,45 +468,45 @@ func ListLatestAWSTargetGroups(config ListLatestAWSTargetGroupsInput) (*semver.V

versionedGroups := map[string]entry{}

if latestVer == nil {
for _, g := range groups {
g := g
var maxVer *semver.Version

var verStr string
for _, g := range groups {
g := g

for _, labelKey := range labelKeys {
verStr = g.Labels[labelKey]
if verStr != "" {
break
}
}
var verStr string

if verStr == "" {
return nil, nil, fmt.Errorf("no semver label found on group: %v", g)
for _, labelKey := range labelKeys {
verStr = g.Labels[labelKey]
if verStr != "" {
break
}
}

ver, err := semver.Parse(verStr)
if err != nil {
return nil, nil, err
}
if verStr == "" {
return nil, nil, fmt.Errorf("no semver label found on group: %v", g)
}

if latestVer == nil {
latestVer = &ver
} else if latestVer.LT(ver) {
latestVer = &ver
}
ver, err := semver.Parse(verStr)
if err != nil {
return nil, nil, err
}

e := versionedGroups[ver.String()]
if maxVer == nil {
maxVer = &ver
} else if maxVer.LT(ver) {
maxVer = &ver
}

e.ver = ver
e.groups = append(e.groups, g)
e := versionedGroups[ver.String()]

versionedGroups[ver.String()] = e
}
e.ver = ver
e.groups = append(e.groups, g)

if latestVer == nil {
return nil, nil, nil
}
versionedGroups[ver.String()] = e
}

if latestVer == nil {
latestVer = maxVer
}

latest := versionedGroups[latestVer.String()]
Expand Down
23 changes: 7 additions & 16 deletions pkg/cell/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,22 @@ func Sync(config SyncInput) error {
labelKeys = []string{okrav1alpha1.DefaultVersionLabelKey}
}

latestVer, latestTGs, err := awstargetgroupset.ListLatestAWSTargetGroups(awstargetgroupset.ListLatestAWSTargetGroupsInput{
v := cell.Spec.Version

desiredVer, latestTGs, err := awstargetgroupset.ListLatestAWSTargetGroups(awstargetgroupset.ListLatestAWSTargetGroupsInput{
ListAWSTargetGroupsInput: awstargetgroupset.ListAWSTargetGroupsInput{
NS: cell.Namespace,
Selector: tgSelector.String(),
},
SemverLabelKeys: labelKeys,
Version: v,
})
if err != nil {
return err
}

var desiredVer *semver.Version

if cell.Spec.Version != "" {
ver, err := semver.Parse(cell.Spec.Version)
if err != nil {
log.Printf("Failed to parse cell.Spec.Version(%s): %v", cell.Spec.Version, err)
return err
}

log.Printf("Using cell.Spec.Version(%s) instead of latest version(%s)", ver, desiredVer)

desiredVer = &ver
} else {
desiredVer = latestVer
if v != "" {
log.Printf("Using cell.Spec.Version(%s) instead of latest version", v)
}

currentTGs, err := awstargetgroupset.ListAWSTargetGroups(awstargetgroupset.ListAWSTargetGroupsInput{
Expand Down Expand Up @@ -164,7 +155,7 @@ func Sync(config SyncInput) error {
threshold = int(*cell.Spec.Replicas)
}

log.Printf("cell=%s/%s, albConfigExists=%v, tgSelector=%s, len(latestTGs)=%d, len(desiredTGs)=%d\n", cell.Namespace, cell.Name, albConfigExists, tgSelector.String(), len(latestTGs), len(desiredTGs))
log.Printf("cell=%s/%s, albConfigExists=%v, tgSelector=%s, len(latestTGs)=%d\n", cell.Namespace, cell.Name, albConfigExists, tgSelector.String(), len(latestTGs))

if numLatestTGs != threshold {
return nil
Expand Down

0 comments on commit 17d46a4

Please sign in to comment.