Skip to content

Commit

Permalink
Do a rolling update when the SDK gets updated (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh authored Jul 12, 2023
1 parent 35c9ba1 commit a0da5cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 0 additions & 3 deletions chart/templates/replicated-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spec:
selector:
matchLabels:
{{- include "replicated.selectorLabels" . | nindent 6 }}
strategy:
# this is to avoid having two replicated instances reporting at the same time for different app versions.
type: Recreate
template:
metadata:
labels:
Expand Down
7 changes: 6 additions & 1 deletion pkg/heartbeat/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import (

func SendAppHeartbeat(sdkStore store.Store) error {
license := sdkStore.GetLicense()
if !canReport(license) {

canReport, err := canReport(license)
if err != nil {
return errors.Wrap(err, "failed to check if can report")
}
if !canReport {
return nil
}

Expand Down
27 changes: 23 additions & 4 deletions pkg/heartbeat/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"net/http"
"strconv"

"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/replicated-sdk/pkg/heartbeat/types"
"github.com/replicatedhq/replicated-sdk/pkg/helm"
"github.com/replicatedhq/replicated-sdk/pkg/logger"
"github.com/replicatedhq/replicated-sdk/pkg/util"
)

Expand All @@ -32,15 +35,31 @@ func InjectHeartbeatInfoHeaders(req *http.Request, heartbeatInfo *types.Heartbea
}
}

func canReport(license *kotsv1beta1.License) bool {
func canReport(license *kotsv1beta1.License) (bool, error) {
if helm.IsHelmManaged() {
sdkHelmRevision := helm.GetReleaseRevision()

helmRelease, err := helm.GetRelease(helm.GetReleaseName())
if err != nil {
return false, errors.Wrap(err, "failed to get release")
}

// don't report from sdk instances that are not associated with the current helm release revision.
// this can happen during a helm upgrade/rollback when a rolling update of the replicated deployment is in progress.
if sdkHelmRevision != helmRelease.Version {
logger.Debugf("not reporting from sdk instance with helm revision %d because current helm release revision is %d\n", sdkHelmRevision, helmRelease.Version)
return false, nil
}
}

if util.IsAirgap() {
return false
return false, nil
}

if util.IsDevEnv() && !util.IsDevLicense(license) {
// don't send reports from our dev env to our production services even if this is a production license
return false
return false, nil
}

return true
return true, nil
}

0 comments on commit a0da5cd

Please sign in to comment.