Skip to content

Commit b73c242

Browse files
authored
[Feature] [Platform] Update Failed Releases (#2002)
1 parent f72a052 commit b73c242

File tree

7 files changed

+108
-41
lines changed

7 files changed

+108
-41
lines changed

.golangci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ linters-settings:
195195
pkg: github.com/arangodb/kube-arangodb/pkg/util/constants
196196
- alias: tcache
197197
pkg: github.com/arangodb/kube-arangodb/pkg/util/tests/cache
198+
- alias: helmRelease
199+
pkg: helm.sh/helm/v3/pkg/release
198200
- alias: apps
199201
pkg: k8s.io/api/apps/v1
200202
- alias: batch

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- (Bugfix) (Platform) Fix topology for Gateways
77
- (Feature) (Platform) Dump CLI switch to Services
88
- (Feature) (Platform) Fix ImagePullSecrets Merge
9+
- (Feature) (Platform) Update Failed Releases
910

1011
## [1.3.2](https://github.com/arangodb/kube-arangodb/tree/1.3.2) (2025-11-20)
1112
- (Bugfix) (Platform) Increase memory limit for Inventory

integrations/scheduler/v2/definition/helpers.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package definition
2222

2323
import (
2424
"helm.sh/helm/v3/pkg/action"
25-
"helm.sh/helm/v3/pkg/release"
25+
helmRelease "helm.sh/helm/v3/pkg/release"
2626
"k8s.io/apimachinery/pkg/labels"
2727
"k8s.io/apimachinery/pkg/runtime/schema"
2828
"k8s.io/apimachinery/pkg/selection"
@@ -31,50 +31,50 @@ import (
3131
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
3232
)
3333

34-
func (i SchedulerV2ReleaseInfoStatus) AsHelmStatus() release.Status {
34+
func (i SchedulerV2ReleaseInfoStatus) AsHelmStatus() helmRelease.Status {
3535
switch i {
3636
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNKNOWN_UNSPECIFIED:
37-
return release.StatusUnknown
37+
return helmRelease.StatusUnknown
3838
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_DEPLOYED:
39-
return release.StatusDeployed
39+
return helmRelease.StatusDeployed
4040
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNINSTALLED:
41-
return release.StatusUninstalled
41+
return helmRelease.StatusUninstalled
4242
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_SUPERSEDED:
43-
return release.StatusSuperseded
43+
return helmRelease.StatusSuperseded
4444
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_FAILED:
45-
return release.StatusFailed
45+
return helmRelease.StatusFailed
4646
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNINSTALLING:
47-
return release.StatusUninstalling
47+
return helmRelease.StatusUninstalling
4848
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_PENDINGINSTALL:
49-
return release.StatusPendingInstall
49+
return helmRelease.StatusPendingInstall
5050
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_PENDINGUPGRADE:
51-
return release.StatusPendingUpgrade
51+
return helmRelease.StatusPendingUpgrade
5252
case SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_PENDINGROLLBACK:
53-
return release.StatusPendingRollback
53+
return helmRelease.StatusPendingRollback
5454
default:
55-
return release.StatusUnknown
55+
return helmRelease.StatusUnknown
5656
}
5757
}
5858

59-
func FromHelmStatus(in release.Status) SchedulerV2ReleaseInfoStatus {
59+
func FromHelmStatus(in helmRelease.Status) SchedulerV2ReleaseInfoStatus {
6060
switch in {
61-
case release.StatusUnknown:
61+
case helmRelease.StatusUnknown:
6262
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNKNOWN_UNSPECIFIED
63-
case release.StatusDeployed:
63+
case helmRelease.StatusDeployed:
6464
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_DEPLOYED
65-
case release.StatusUninstalled:
65+
case helmRelease.StatusUninstalled:
6666
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNINSTALLED
67-
case release.StatusSuperseded:
67+
case helmRelease.StatusSuperseded:
6868
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_SUPERSEDED
69-
case release.StatusFailed:
69+
case helmRelease.StatusFailed:
7070
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_FAILED
71-
case release.StatusUninstalling:
71+
case helmRelease.StatusUninstalling:
7272
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNINSTALLING
73-
case release.StatusPendingInstall:
73+
case helmRelease.StatusPendingInstall:
7474
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_PENDINGINSTALL
75-
case release.StatusPendingUpgrade:
75+
case helmRelease.StatusPendingUpgrade:
7676
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_PENDINGUPGRADE
77-
case release.StatusPendingRollback:
77+
case helmRelease.StatusPendingRollback:
7878
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_PENDINGROLLBACK
7979
default:
8080
return SchedulerV2ReleaseInfoStatus_SCHEDULER_V2_RELEASE_INFO_STATUS_UNKNOWN_UNSPECIFIED

pkg/apis/platform/v1alpha1/service_status_release.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
package v1alpha1
2222

2323
import (
24-
"helm.sh/helm/v3/pkg/release"
24+
helmRelease "helm.sh/helm/v3/pkg/release"
2525
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
)
2727

@@ -33,7 +33,7 @@ type ArangoPlatformServiceStatusRelease struct {
3333
}
3434

3535
type ArangoPlatformServiceStatusReleaseInfo struct {
36-
FirstDeployed *meta.Time `json:"first_deployed,omitempty"`
37-
LastDeployed *meta.Time `json:"last_deployed,omitempty"`
38-
Status release.Status `json:"status,omitempty"`
36+
FirstDeployed *meta.Time `json:"first_deployed,omitempty"`
37+
LastDeployed *meta.Time `json:"last_deployed,omitempty"`
38+
Status helmRelease.Status `json:"status,omitempty"`
3939
}

pkg/apis/platform/v1beta1/service_status_release.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
package v1beta1
2222

2323
import (
24-
"helm.sh/helm/v3/pkg/release"
24+
helmRelease "helm.sh/helm/v3/pkg/release"
2525
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
27+
"github.com/arangodb/kube-arangodb/pkg/util"
2628
)
2729

2830
type ArangoPlatformServiceStatusRelease struct {
@@ -32,8 +34,35 @@ type ArangoPlatformServiceStatusRelease struct {
3234
Info ArangoPlatformServiceStatusReleaseInfo `json:"info"`
3335
}
3436

37+
func (a *ArangoPlatformServiceStatusRelease) Compare(o *ArangoPlatformServiceStatusRelease) bool {
38+
if a == nil && o == nil {
39+
return true
40+
}
41+
if a == nil || o == nil {
42+
return false
43+
}
44+
45+
return a.Name == o.Name &&
46+
a.Version == o.Version &&
47+
a.Hash == o.Hash &&
48+
a.Info.Compare(&o.Info)
49+
}
50+
3551
type ArangoPlatformServiceStatusReleaseInfo struct {
36-
FirstDeployed *meta.Time `json:"first_deployed,omitempty"`
37-
LastDeployed *meta.Time `json:"last_deployed,omitempty"`
38-
Status release.Status `json:"status,omitempty"`
52+
FirstDeployed *meta.Time `json:"first_deployed,omitempty"`
53+
LastDeployed *meta.Time `json:"last_deployed,omitempty"`
54+
Status helmRelease.Status `json:"status,omitempty"`
55+
}
56+
57+
func (a *ArangoPlatformServiceStatusReleaseInfo) Compare(o *ArangoPlatformServiceStatusReleaseInfo) bool {
58+
if a == nil && o == nil {
59+
return true
60+
}
61+
if a == nil || o == nil {
62+
return false
63+
}
64+
65+
return util.TimeCompareEqualPointer(a.FirstDeployed, o.FirstDeployed) &&
66+
util.TimeCompareEqualPointer(a.LastDeployed, o.LastDeployed) &&
67+
a.Status == o.Status
3968
}

pkg/handlers/platform/service/handler.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"helm.sh/helm/v3/pkg/action"
28+
helmRelease "helm.sh/helm/v3/pkg/release"
2829
apiErrors "k8s.io/apimachinery/pkg/api/errors"
2930
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/client-go/kubernetes"
@@ -413,7 +414,41 @@ func (h *handler) HandleRelease(ctx context.Context, item operation.Item, extens
413414
return true, operator.Reconcile("Release Upgraded")
414415
}
415416

416-
return false, nil
417+
if s := extractReleaseStatus(release, expectedChecksum); !s.Compare(status.Release) {
418+
logger.WrapObj(item).Info("Release Update")
419+
status.Release = s
420+
return true, operator.Reconcile("Release Updated")
421+
}
422+
423+
switch status.Release.Info.Status {
424+
case helmRelease.StatusDeployed:
425+
return false, nil
426+
427+
case helmRelease.StatusFailed:
428+
// Try to upgrade
429+
logger.WrapObj(item).Info("Upgrade Helm Release")
430+
431+
_, err = h.helm.Upgrade(ctx, extension.GetName(), helm.Chart(status.ChartInfo.Definition), helm.Values(status.Values), func(in *action.Upgrade) {
432+
in.Namespace = extension.GetNamespace()
433+
434+
in.Labels = labels.GetLabels(status.Deployment.GetName(), status.Chart.GetName())
435+
436+
in.Timeout = 20 * time.Minute
437+
})
438+
if err != nil {
439+
h.eventRecorder.Warning(extension, "Release Upgrade Failed", "Release upgrade failed: %s", err.Error())
440+
441+
return false, err
442+
}
443+
444+
status.Release = extractReleaseStatus(release, expectedChecksum)
445+
446+
h.eventRecorder.Normal(extension, "Release Upgraded", "Release upgraded with version %d on chart %s (%s)", status.Release.Version, status.ChartInfo.Details.Name, status.ChartInfo.Details.Version)
447+
448+
return true, operator.Reconcile("Release Upgraded")
449+
}
450+
451+
return false, operator.Stop("Invalid release status: %s", status.Release.Info.Status)
417452
}
418453

419454
func extractReleaseStatus(in *helm.Release, hash string) *platformApi.ArangoPlatformServiceStatusRelease {

pkg/util/k8sutil/helm/types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"time"
2626

2727
"helm.sh/helm/v3/pkg/chart"
28-
"helm.sh/helm/v3/pkg/release"
28+
helmRelease "helm.sh/helm/v3/pkg/release"
2929
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -34,7 +34,7 @@ import (
3434
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3535
)
3636

37-
func fromHelmRelease(in *release.Release) (Release, error) {
37+
func fromHelmRelease(in *helmRelease.Release) (Release, error) {
3838
var r Release
3939

4040
if in == nil {
@@ -88,7 +88,7 @@ func fromHelmReleaseChartMetadata(in *chart.Metadata) *ReleaseChartMetadata {
8888
return &r
8989
}
9090

91-
func fromHelmReleaseInfo(in *release.Info) (ReleaseInfo, error) {
91+
func fromHelmReleaseInfo(in *helmRelease.Info) (ReleaseInfo, error) {
9292
var r ReleaseInfo
9393

9494
if in == nil {
@@ -191,13 +191,13 @@ func (r *ReleaseChartMetadata) GetVersion() string {
191191
}
192192

193193
type ReleaseInfo struct {
194-
FirstDeployed time.Time `json:"first_deployed,omitempty"`
195-
LastDeployed time.Time `json:"last_deployed,omitempty"`
196-
Deleted time.Time `json:"deleted,omitempty"`
197-
Description string `json:"description,omitempty"`
198-
Status release.Status `json:"status,omitempty"`
199-
Notes string `json:"notes,omitempty"`
200-
Resources Resources `json:"resources,omitempty"`
194+
FirstDeployed time.Time `json:"first_deployed,omitempty"`
195+
LastDeployed time.Time `json:"last_deployed,omitempty"`
196+
Deleted time.Time `json:"deleted,omitempty"`
197+
Description string `json:"description,omitempty"`
198+
Status helmRelease.Status `json:"status,omitempty"`
199+
Notes string `json:"notes,omitempty"`
200+
Resources Resources `json:"resources,omitempty"`
201201
}
202202

203203
type Resources []Resource

0 commit comments

Comments
 (0)