Skip to content

Commit

Permalink
Add src and image to envs (#599) (#602)
Browse files Browse the repository at this point in the history
* Show component names in pipeline clone step

* Show component tags

* Added the command deploy to the Makefile

* Extended linter timout

* Fixed radix-operator version and unit-tags
  • Loading branch information
satr authored Mar 5, 2024
1 parent c6e4ba5 commit 8ec999d
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 196 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test:

.PHONY: lint
lint: bootstrap
golangci-lint run --max-same-issues 0
golangci-lint run --max-same-issues 0 --timeout 10m

build-kaniko:
docker run --rm -it -v $(CURRENT_FOLDER):/workspace gcr.io/kaniko-project/executor:latest --destination=$(DOCKER_REGISTRY)/radix-api-server:3hv6o --snapshotMode=time --cache=true
Expand Down Expand Up @@ -64,6 +64,9 @@ docker-push: $(addsuffix -push,$(IMAGES))
az acr login --name $(CONTAINER_REPO)
docker push $(DOCKER_REGISTRY)/$*-server:$(IMAGE_TAG)

.PHONY: deploy
deploy: $(addsuffix -image,$(IMAGES)) $(addsuffix -push,$(IMAGES))

HAS_SWAGGER := $(shell command -v swagger;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
HAS_MOCKGEN := $(shell command -v mockgen;)
Expand Down
92 changes: 47 additions & 45 deletions api/applications/applications_controller_test.go

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions api/deployments/component_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createGetComponentsEndpoint(appName, deployName string) string {

func TestGetComponents_non_existing_app(t *testing.T) {
// Setup
_, controllerTestUtils, _, _, _, _ := setupTest(t)
_, controllerTestUtils, _, _, _, _, _ := setupTest(t)

endpoint := createGetComponentsEndpoint(anyAppName, anyDeployName)

Expand All @@ -43,7 +43,7 @@ func TestGetComponents_non_existing_app(t *testing.T) {
}

func TestGetComponents_non_existing_deployment(t *testing.T) {
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyApplication(operatorUtils.
ARadixApplication().
WithAppName(anyAppName))
Expand All @@ -63,7 +63,7 @@ func TestGetComponents_non_existing_deployment(t *testing.T) {

func TestGetComponents_active_deployment(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, kubeclient, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyDeployment(operatorUtils.
ARadixDeployment().
WithJobComponents(
Expand Down Expand Up @@ -102,8 +102,8 @@ func TestGetComponents_active_deployment(t *testing.T) {

func TestGetComponents_WithVolumeMount_ContainsVolumeMountSecrets(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient := setupTest(t)
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, operatorUtils.ARadixDeployment().
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient, certClient := setupTest(t)
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, certClient, operatorUtils.ARadixDeployment().
WithAppName("any-app").
WithEnvironment("prod").
WithDeploymentName(anyDeployName).
Expand Down Expand Up @@ -161,8 +161,8 @@ func TestGetComponents_WithVolumeMount_ContainsVolumeMountSecrets(t *testing.T)

func TestGetComponents_WithTwoVolumeMounts_ContainsTwoVolumeMountSecrets(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient := setupTest(t)
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, operatorUtils.ARadixDeployment().
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient, certClient := setupTest(t)
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, certClient, operatorUtils.ARadixDeployment().
WithAppName("any-app").
WithEnvironment("prod").
WithDeploymentName(anyDeployName).
Expand Down Expand Up @@ -210,8 +210,8 @@ func TestGetComponents_WithTwoVolumeMounts_ContainsTwoVolumeMountSecrets(t *test

func TestGetComponents_OAuth2(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient := setupTest(t)
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, operatorUtils.ARadixDeployment().
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient, certClient := setupTest(t)
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, certClient, operatorUtils.ARadixDeployment().
WithAppName("any-app").
WithEnvironment("prod").
WithDeploymentName(anyDeployName).
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestGetComponents_OAuth2(t *testing.T) {

func TestGetComponents_inactive_deployment(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, kubeclient, _, _, _, _ := setupTest(t)

initialDeploymentCreated, _ := radixutils.ParseTimestamp("2018-11-12T11:45:26Z")
activeDeploymentCreated, _ := radixutils.ParseTimestamp("2018-11-14T11:45:26Z")
Expand Down Expand Up @@ -335,7 +335,7 @@ func getPodSpec(podName, radixComponentLabel string) *corev1.Pod {

func TestGetComponents_success(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyDeployment(operatorUtils.
ARadixDeployment().
WithAppName(anyAppName).
Expand All @@ -360,7 +360,7 @@ func TestGetComponents_success(t *testing.T) {

func TestGetComponents_ReplicaStatus_Failing(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, kubeclient, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyDeployment(operatorUtils.
ARadixDeployment().
WithAppName(anyAppName).
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestGetComponents_ReplicaStatus_Failing(t *testing.T) {

func TestGetComponents_ReplicaStatus_Running(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, kubeclient, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyDeployment(operatorUtils.
ARadixDeployment().
WithAppName(anyAppName).
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestGetComponents_ReplicaStatus_Running(t *testing.T) {

func TestGetComponents_ReplicaStatus_Starting(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, kubeclient, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyDeployment(operatorUtils.
ARadixDeployment().
WithAppName(anyAppName).
Expand Down Expand Up @@ -496,7 +496,7 @@ func TestGetComponents_ReplicaStatus_Starting(t *testing.T) {

func TestGetComponents_ReplicaStatus_Pending(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, kubeclient, _, _, _, _ := setupTest(t)
_, err := commonTestUtils.ApplyDeployment(operatorUtils.
ARadixDeployment().
WithAppName(anyAppName).
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestGetComponents_ReplicaStatus_Pending(t *testing.T) {
func TestGetComponents_WithHorizontalScaling(t *testing.T) {
// Setup

commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient := setupTest(t)
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient, certClient := setupTest(t)
testScenarios := []struct {
name string
deploymentName string
Expand All @@ -560,7 +560,7 @@ func TestGetComponents_WithHorizontalScaling(t *testing.T) {

for _, scenario := range testScenarios {
t.Run(scenario.name, func(t *testing.T) {
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, operatorUtils.ARadixDeployment().
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, certClient, operatorUtils.ARadixDeployment().
WithAppName(anyAppName).
WithEnvironment("prod").
WithDeploymentName(scenario.deploymentName).
Expand Down Expand Up @@ -597,9 +597,9 @@ func TestGetComponents_WithHorizontalScaling(t *testing.T) {

func TestGetComponents_WithIdentity(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient := setupTest(t)
commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretProviderClient, certClient := setupTest(t)

err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, operatorUtils.ARadixDeployment().
err := utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretProviderClient, certClient, operatorUtils.ARadixDeployment().
WithAppName("any-app").
WithEnvironment("prod").
WithDeploymentName(anyDeployName).
Expand Down
27 changes: 14 additions & 13 deletions api/deployments/deployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

certfake "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned/fake"
"github.com/equinor/radix-operator/pkg/apis/kube"
"github.com/stretchr/testify/require"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -34,15 +35,15 @@ func createGetLogEndpoint(appName, podName string) string {
return fmt.Sprintf("/api/v1/applications/%s/deployments/any/components/any/replicas/%s/logs", appName, podName)
}

func setupTest(t *testing.T) (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, secretsstorevclient.Interface) {
commonTestUtils, kubeclient, radixClient, prometheusClient, secretproviderclient := apiUtils.SetupTest(t)
func setupTest(t *testing.T) (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, secretsstorevclient.Interface, *certfake.Clientset) {
commonTestUtils, kubeclient, radixClient, prometheusClient, secretproviderclient, certClient := apiUtils.SetupTest(t)
// controllerTestUtils is used for issuing HTTP request and processing responses
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixClient, secretproviderclient, NewDeploymentController())
return commonTestUtils, &controllerTestUtils, kubeclient, radixClient, prometheusClient, secretproviderclient
return commonTestUtils, &controllerTestUtils, kubeclient, radixClient, prometheusClient, secretproviderclient, certClient
}
func TestGetPodLog_no_radixconfig(t *testing.T) {
// Setup
_, controllerTestUtils, _, _, _, _ := setupTest(t)
_, controllerTestUtils, _, _, _, _, _ := setupTest(t)

endpoint := createGetLogEndpoint(anyAppName, anyPodName)

Expand All @@ -56,7 +57,7 @@ func TestGetPodLog_no_radixconfig(t *testing.T) {
}

func TestGetPodLog_No_Pod(t *testing.T) {
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
endpoint := createGetLogEndpoint(anyAppName, anyPodName)

_, err := commonTestUtils.ApplyApplication(builders.
Expand All @@ -77,7 +78,7 @@ func TestGetPodLog_No_Pod(t *testing.T) {

func TestGetDeployments_Filter_FilterIsApplied(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)

_, err := commonTestUtils.ApplyDeployment(builders.
ARadixDeployment().
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestGetDeployments_Filter_FilterIsApplied(t *testing.T) {
}

func TestGetDeployments_NoApplicationRegistered(t *testing.T) {
_, controllerTestUtils, _, _, _, _ := setupTest(t)
_, controllerTestUtils, _, _, _, _, _ := setupTest(t)
responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deployments", anyAppName))
response := <-responseChannel

Expand All @@ -188,7 +189,7 @@ func TestGetDeployments_OneEnvironment_SortedWithFromTo(t *testing.T) {
annotations := make(map[string]string)
annotations[kube.RadixGitTagsAnnotation] = gitTags
annotations[kube.RadixCommitAnnotation] = gitCommitHash
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
err := setupGetDeploymentsTest(commonTestUtils, anyAppName, deploymentOneImage, deploymentTwoImage, deploymentThreeImage, deploymentOneCreated, deploymentTwoCreated, deploymentThreeCreated, []string{"dev"}, annotations)
require.NoError(t, err)

Expand Down Expand Up @@ -228,7 +229,7 @@ func TestGetDeployments_OneEnvironment_Latest(t *testing.T) {
annotations := make(map[string]string)
annotations[kube.RadixGitTagsAnnotation] = "some tags go here"
annotations[kube.RadixCommitAnnotation] = "gfsjrgnsdkfgnlnfgdsMYCOMMIT"
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
err := setupGetDeploymentsTest(commonTestUtils, anyAppName, deploymentOneImage, deploymentTwoImage, deploymentThreeImage, deploymentOneCreated, deploymentTwoCreated, deploymentThreeCreated, []string{"dev"}, annotations)
require.NoError(t, err)

Expand Down Expand Up @@ -258,7 +259,7 @@ func TestGetDeployments_TwoEnvironments_SortedWithFromTo(t *testing.T) {
annotations := make(map[string]string)
annotations[kube.RadixGitTagsAnnotation] = "some tags go here"
annotations[kube.RadixCommitAnnotation] = "gfsjrgnsdkfgnlnfgdsMYCOMMIT"
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
err := setupGetDeploymentsTest(commonTestUtils, anyAppName, deploymentOneImage, deploymentTwoImage, deploymentThreeImage, deploymentOneCreated, deploymentTwoCreated, deploymentThreeCreated, []string{"dev", "prod"}, annotations)
require.NoError(t, err)

Expand Down Expand Up @@ -296,7 +297,7 @@ func TestGetDeployments_TwoEnvironments_Latest(t *testing.T) {
annotations := make(map[string]string)
annotations[kube.RadixGitTagsAnnotation] = "some tags go here"
annotations[kube.RadixCommitAnnotation] = "gfsjrgnsdkfgnlnfgdsMYCOMMIT"
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
err := setupGetDeploymentsTest(commonTestUtils, anyAppName, deploymentOneImage, deploymentTwoImage, deploymentThreeImage, deploymentOneCreated, deploymentTwoCreated, deploymentThreeCreated, []string{"dev", "prod"}, annotations)
require.NoError(t, err)

Expand All @@ -318,7 +319,7 @@ func TestGetDeployments_TwoEnvironments_Latest(t *testing.T) {
}

func TestGetDeployment_NoApplicationRegistered(t *testing.T) {
_, controllerTestUtils, _, _, _, _ := setupTest(t)
_, controllerTestUtils, _, _, _, _, _ := setupTest(t)
responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deployments/%s", anyAppName, anyDeployName))
response := <-responseChannel

Expand All @@ -329,7 +330,7 @@ func TestGetDeployment_NoApplicationRegistered(t *testing.T) {

func TestGetDeployment_TwoDeploymentsFirstDeployment_ReturnsDeploymentWithComponents(t *testing.T) {
// Setup
commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest(t)
commonTestUtils, controllerTestUtils, _, _, _, _, _ := setupTest(t)
anyAppName := "any-app"
anyEnvironment := "dev"
anyDeployment1Name := "abcdef"
Expand Down
1 change: 1 addition & 0 deletions api/deployments/models/component_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func (b *componentBuilder) BuildComponent() (*Component, error) {
ExternalDNS: b.externalDNS,
HorizontalScalingSummary: b.hpa,
CommitID: variables[defaults.RadixCommitHashEnvironmentVariable],
GitTags: variables[defaults.RadixGitTagsEnvironmentVariable],
}, b.buildError()
}

Expand Down
6 changes: 6 additions & 0 deletions api/deployments/models/component_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ type Component struct {
// example: 4faca8595c5283a9d0f17a623b9255a0d9866a2e
CommitID string `json:"commitID,omitempty"`

// GitTags the git tags that the git commit hash points to
//
// required: false
// example: "v1.22.1 v1.22.3"
GitTags string `json:"gitTags,omitempty"`

// SkipDeployment The component should not be deployed, but used existing
//
// required: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *externalDnsTestSuite) buildCertificate(certCN, issuerCN string, dnsName
func (s *externalDnsTestSuite) SetupTest() {
ctrl := gomock.NewController(s.T())
s.tlsValidator = tlsvalidationmock.NewMockValidator(ctrl)
s.commonTestUtils, s.envvironmentTestUtils, _, s.kubeClient, s.radixClient, _, s.secretProviderClient = setupTest(s.T(), []EnvironmentHandlerOptions{WithTLSValidator(s.tlsValidator)})
s.commonTestUtils, s.envvironmentTestUtils, _, s.kubeClient, s.radixClient, _, s.secretProviderClient, _ = setupTest(s.T(), []EnvironmentHandlerOptions{WithTLSValidator(s.tlsValidator)})

s.appName, s.componentName, s.environmentName, s.alias = "any-app", "backend", "dev", "cdn.myalias.com"

Expand Down
2 changes: 1 addition & 1 deletion api/environments/environment_controller_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (s *secretHandlerTestSuite) assertSecrets(scenario *getSecretScenario, secr
}

func (s *secretHandlerTestSuite) prepareTestRun(scenario *getSecretScenario, appName, envName, deploymentName string) *controllertest.Utils {
_, environmentControllerTestUtils, _, kubeClient, radixClient, _, secretClient := setupTest(s.T(), nil)
_, environmentControllerTestUtils, _, kubeClient, radixClient, _, secretClient, _ := setupTest(s.T(), nil)
_, err := radixClient.RadixV1().RadixRegistrations().Create(context.Background(), &v1.RadixRegistration{ObjectMeta: metav1.ObjectMeta{Name: appName}}, metav1.CreateOptions{})
require.NoError(s.T(), err)
appAppNamespace := operatorutils.GetAppNamespace(appName)
Expand Down
Loading

0 comments on commit 8ec999d

Please sign in to comment.