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

release radix-api #699

Merged
merged 3 commits into from
Oct 30, 2024
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
4 changes: 1 addition & 3 deletions api/applications/applications_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -77,7 +76,6 @@ func setupTestWithFactory(t *testing.T, handlerFactory ApplicationHandlerFactory
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient)
err := commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)
require.NoError(t, err)
_ = os.Setenv(defaults.ActiveClusternameEnvironmentVariable, clusterName)
prometheusHandlerMock := createPrometheusHandlerMock(t, radixclient, nil)

// controllerTestUtils is used for issuing HTTP request and processing responses
Expand Down Expand Up @@ -974,6 +972,7 @@ func TestGetApplication_WithEnvironments(t *testing.T) {
WithEnvironmentName(anyOrphanedEnvironment))
orphanedRe.Status.Reconciled = metav1.Now()
orphanedRe.Status.Orphaned = true
orphanedRe.Status.OrphanedTimestamp = pointers.Ptr(metav1.Now())
_, err = radix.RadixV1().RadixEnvironments().Update(context.Background(), orphanedRe, metav1.UpdateOptions{})
require.NoError(t, err)

Expand Down Expand Up @@ -1684,7 +1683,6 @@ func TestHandleTriggerPipeline_Promote_JobHasCorrectParameters(t *testing.T) {
const (
appName = "an-app"
commitId = "475f241c-478b-49da-adfb-3c336aaab8d2"
deploymentName = "a-deployment"
fromEnvironment = "origin"
toEnvironment = "target"
)
Expand Down
49 changes: 5 additions & 44 deletions api/buildstatus/build_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package buildstatus
import (
"errors"
"io"
"os"
"testing"
"time"

Expand All @@ -15,7 +14,6 @@ import (
certclientfake "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned/fake"
controllertest "github.com/equinor/radix-api/api/test"
"github.com/equinor/radix-api/api/test/mock"
"github.com/equinor/radix-operator/pkg/apis/defaults"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
commontest "github.com/equinor/radix-operator/pkg/apis/test"
builders "github.com/equinor/radix-operator/pkg/apis/utils"
Expand Down Expand Up @@ -43,8 +41,6 @@ func setupTest(t *testing.T) (*commontest.Utils, *kubefake.Clientset, *radixfake
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient)
err := commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)
require.NoError(t, err)
_ = os.Setenv(defaults.ActiveClusternameEnvironmentVariable, clusterName)

return &commonTestUtils, kubeclient, radixclient, kedaClient, secretproviderclient, certClient
}

Expand Down Expand Up @@ -102,7 +98,7 @@ func TestGetBuildStatus(t *testing.T) {
expected := []byte("badge")

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
Return(expected, nil).
Times(1)

Expand All @@ -125,16 +121,7 @@ func TestGetBuildStatus(t *testing.T) {

fakeBuildStatus := mock.NewMockPipelineBadge(ctrl)

var actualCondition v1.RadixJobCondition
var actualPipeline v1.RadixPipelineType

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) {
actualCondition = c
actualPipeline = p
return nil, nil
})
fakeBuildStatus.EXPECT().GetBadge(gomock.Any(), v1.JobRunning, v1.BuildDeploy).Return(nil, nil).Times(1)

mockValidator := authnmock.NewMockValidatorInterface(gomock.NewController(t))
mockValidator.EXPECT().ValidateToken(gomock.Any(), gomock.Any()).AnyTimes().Return(controllertest.NewTestPrincipal(true), nil)
Expand All @@ -144,8 +131,6 @@ func TestGetBuildStatus(t *testing.T) {
response := <-responseChannel

assert.Equal(t, response.Result().StatusCode, 200)
assert.Equal(t, v1.JobRunning, actualCondition)
assert.Equal(t, v1.BuildDeploy, actualPipeline)
})

t.Run("deploy in master - JobRunning", func(t *testing.T) {
Expand All @@ -154,17 +139,7 @@ func TestGetBuildStatus(t *testing.T) {
defer ctrl.Finish()

fakeBuildStatus := mock.NewMockPipelineBadge(ctrl)

var actualCondition v1.RadixJobCondition
var actualPipeline v1.RadixPipelineType

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) {
actualCondition = c
actualPipeline = p
return nil, nil
})
fakeBuildStatus.EXPECT().GetBadge(gomock.Any(), v1.JobSucceeded, v1.Deploy).Return(nil, nil).Times(1)

mockValidator := authnmock.NewMockValidatorInterface(gomock.NewController(t))
mockValidator.EXPECT().ValidateToken(gomock.Any(), gomock.Any()).AnyTimes().Return(controllertest.NewTestPrincipal(true), nil)
Expand All @@ -174,8 +149,6 @@ func TestGetBuildStatus(t *testing.T) {
response := <-responseChannel

assert.Equal(t, response.Result().StatusCode, 200)
assert.Equal(t, v1.JobSucceeded, actualCondition)
assert.Equal(t, v1.Deploy, actualPipeline)
})

t.Run("promote in master - JobFailed", func(t *testing.T) {
Expand All @@ -184,17 +157,7 @@ func TestGetBuildStatus(t *testing.T) {
defer ctrl.Finish()

fakeBuildStatus := mock.NewMockPipelineBadge(ctrl)

var actualCondition v1.RadixJobCondition
var actualPipeline v1.RadixPipelineType

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) {
actualCondition = c
actualPipeline = p
return nil, nil
})
fakeBuildStatus.EXPECT().GetBadge(gomock.Any(), v1.JobFailed, v1.Promote).Return(nil, nil).Times(1)

mockValidator := authnmock.NewMockValidatorInterface(gomock.NewController(t))
mockValidator.EXPECT().ValidateToken(gomock.Any(), gomock.Any()).AnyTimes().Return(controllertest.NewTestPrincipal(true), nil)
Expand All @@ -204,8 +167,6 @@ func TestGetBuildStatus(t *testing.T) {
response := <-responseChannel

assert.Equal(t, response.Result().StatusCode, 200)
assert.Equal(t, v1.JobFailed, actualCondition)
assert.Equal(t, v1.Promote, actualPipeline)
})

t.Run("return status 500", func(t *testing.T) {
Expand All @@ -216,7 +177,7 @@ func TestGetBuildStatus(t *testing.T) {
fakeBuildStatus := mock.NewMockPipelineBadge(ctrl)

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil, errors.New("error")).
Times(1)

Expand Down
2 changes: 2 additions & 0 deletions api/buildstatus/buildstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/equinor/radix-api/models"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/gorilla/mux"
"github.com/rs/zerolog/log"
)

const rootPath = "/applications/{appName}/environments/{envName}"
Expand Down Expand Up @@ -77,6 +78,7 @@ func (bsc *buildStatusController) GetBuildStatus(accounts models.Accounts, w htt
buildStatus, err := buildStatusHandler.GetBuildStatusForApplication(r.Context(), appName, env, pipeline)

if err != nil {
log.Error().Err(err).Msg("Error getting build status")
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
2 changes: 1 addition & 1 deletion api/buildstatus/buildstatus_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (handler BuildStatusHandler) GetBuildStatusForApplication(ctx context.Conte
buildCondition = latestPipelineJob.Status.Condition
}

output, err = handler.pipelineBadge.GetBadge(buildCondition, v1.RadixPipelineType(pipeline))
output, err = handler.pipelineBadge.GetBadge(ctx, buildCondition, v1.RadixPipelineType(pipeline))
if err != nil {
return nil, err
}
Expand Down
91 changes: 51 additions & 40 deletions api/buildstatus/models/badges/build-status.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading