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

Require kuberpult AND argocd version to mark app as deployed #1197

Merged
merged 1 commit into from
Dec 6, 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
10 changes: 7 additions & 3 deletions services/rollout-service/pkg/service/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type appState struct {

func (a *appState) applyArgoEvent(ev *ArgoEvent) *BroadcastEvent {
status := rolloutStatus(ev)
if a.rolloutStatus != status || a.argocdVersion == nil || (ev.Version != nil && a.argocdVersion.Version != ev.Version.Version) {
if a.rolloutStatus != status || !a.argocdVersion.Equal(ev.Version) {
a.rolloutStatus = status
a.argocdVersion = ev.Version
return a.getEvent(ev.Application, ev.Environment)
Expand All @@ -56,7 +56,7 @@ func (a *appState) applyArgoEvent(ev *ArgoEvent) *BroadcastEvent {
}

func (a *appState) applyKuberpultEvent(ev *versions.KuberpultEvent) *BroadcastEvent {
if a.kuberpultVersion == nil || a.kuberpultVersion.Version != ev.Version.Version || a.isProduction == nil || *a.isProduction != ev.IsProduction {
if !a.argocdVersion.Equal(ev.Version) || a.isProduction == nil || *a.isProduction != ev.IsProduction {
a.kuberpultVersion = ev.Version
a.environmentGroup = ev.EnvironmentGroup
a.team = ev.Team
Expand All @@ -68,7 +68,11 @@ func (a *appState) applyKuberpultEvent(ev *versions.KuberpultEvent) *BroadcastEv

func (a *appState) getEvent(application, environment string) *BroadcastEvent {
rs := a.rolloutStatus
if a.kuberpultVersion != nil && a.argocdVersion != nil && a.kuberpultVersion.Version != a.argocdVersion.Version {
if a.kuberpultVersion == nil || a.argocdVersion == nil {
if rs == api.RolloutStatus_RolloutStatusSuccesful {
rs = api.RolloutStatus_RolloutStatusUnknown
}
} else if a.kuberpultVersion.Version != a.argocdVersion.Version {
rs = api.RolloutStatus_RolloutStatusPending
}
return &BroadcastEvent{
Expand Down
49 changes: 46 additions & 3 deletions services/rollout-service/pkg/service/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ func TestBroadcast(t *testing.T) {
SyncStatusCode: v1alpha1.SyncStatusCodeSynced,
HealthStatusCode: health.HealthStatusHealthy,
},
},
{
VersionEvent: &versions.KuberpultEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 1},
},

ExpectStatus: &RolloutStatusSuccesful,
},
Expand Down Expand Up @@ -138,7 +145,7 @@ func TestBroadcast(t *testing.T) {
HealthStatusCode: health.HealthStatusHealthy,
},

ExpectStatus: &RolloutStatusSuccesful,
ExpectStatus: &RolloutStatusUnknown,
},
{
ArgoEvent: &ArgoEvent{
Expand All @@ -156,6 +163,15 @@ func TestBroadcast(t *testing.T) {
{
Name: "app syncing and becomming healthy",
Steps: []step{
{
VersionEvent: &versions.KuberpultEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 1},
},

ExpectStatus: &RolloutStatusUnknown,
},
{
ArgoEvent: &ArgoEvent{
Application: "foo",
Expand All @@ -167,11 +183,20 @@ func TestBroadcast(t *testing.T) {

ExpectStatus: &RolloutStatusSuccesful,
},
{
VersionEvent: &versions.KuberpultEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 2},
},

ExpectStatus: &RolloutStatusPending,
},
{
ArgoEvent: &ArgoEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 1},
Version: &versions.VersionInfo{Version: 2},
SyncStatusCode: v1alpha1.SyncStatusCodeOutOfSync,
HealthStatusCode: health.HealthStatusHealthy,
},
Expand All @@ -182,7 +207,7 @@ func TestBroadcast(t *testing.T) {
ArgoEvent: &ArgoEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 1},
Version: &versions.VersionInfo{Version: 2},
SyncStatusCode: v1alpha1.SyncStatusCodeOutOfSync,
HealthStatusCode: health.HealthStatusProgressing,
},
Expand All @@ -205,6 +230,15 @@ func TestBroadcast(t *testing.T) {
{
Name: "app becomming unhealthy and recovers",
Steps: []step{
{
VersionEvent: &versions.KuberpultEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 1},
},

ExpectStatus: &RolloutStatusUnknown,
},
{
ArgoEvent: &ArgoEvent{
Application: "foo",
Expand Down Expand Up @@ -281,6 +315,15 @@ func TestBroadcast(t *testing.T) {
{
Name: "healthy app switches to pending when a new version in kuberpult is deployed",
Steps: []step{
{
VersionEvent: &versions.KuberpultEvent{
Application: "foo",
Environment: "bar",
Version: &versions.VersionInfo{Version: 1},
},

ExpectStatus: &RolloutStatusUnknown,
},
{
ArgoEvent: &ArgoEvent{
Application: "foo",
Expand Down
2 changes: 1 addition & 1 deletion services/rollout-service/pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestArgoConection(t *testing.T) {
Name: "stops when ctx closes in the watch call",
Steps: []step{
{
RecvErr: status.Error(codes.Canceled, "context cancelled"),
RecvErr: status.Error(codes.Canceled, "context cancelled"),
CancelContext: true,
},
},
Expand Down
10 changes: 10 additions & 0 deletions services/rollout-service/pkg/versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ type VersionInfo struct {
DeployedAt time.Time
}

func (v *VersionInfo) Equal(w *VersionInfo) bool {
if v == nil {
return w == nil
}
if w == nil {
return false
}
return v.Version == w.Version
}

// GetVersion implements VersionClient
func (v *versionClient) GetVersion(ctx context.Context, revision, environment, application string) (*VersionInfo, error) {
var overview *api.GetOverviewResponse
Expand Down
4 changes: 2 additions & 2 deletions services/rollout-service/pkg/versions/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func TestVersionClientStream(t *testing.T) {
{
Overview: testOverview,

ExpectReady: true,
ExpectReady: true,
},
{
RecvErr: status.Error(codes.Canceled, "context cancelled"),
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestVersionClientStream(t *testing.T) {
{
RecvErr: fmt.Errorf("no"),

ExpectReady: false,
ExpectReady: false,
},
{
Overview: emptyTestOverview,
Expand Down
Loading