Skip to content

Commit

Permalink
fic test build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Sep 27, 2024
1 parent 7c07711 commit 2538465
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 219 deletions.
23 changes: 12 additions & 11 deletions api/applications/applications_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
jobModels "github.com/equinor/radix-api/api/jobs/models"
controllertest "github.com/equinor/radix-api/api/test"
"github.com/equinor/radix-api/api/utils"
"github.com/equinor/radix-api/internal/config"
"github.com/equinor/radix-api/models"
radixhttp "github.com/equinor/radix-common/net/http"
radixutils "github.com/equinor/radix-common/utils"
Expand Down Expand Up @@ -52,7 +53,7 @@ const (

func setupTest(t *testing.T, requireAppConfigurationItem, requireAppADGroups bool) (*commontest.Utils, *controllertest.Utils, *kubefake.Clientset, *radixfake.Clientset, *kedafake.Clientset, *prometheusfake.Clientset, *secretproviderfake.Clientset, *certfake.Clientset) {
return setupTestWithFactory(t, newTestApplicationHandlerFactory(
ApplicationHandlerConfig{RequireAppConfigurationItem: requireAppConfigurationItem, RequireAppADGroups: requireAppADGroups},
config.Config{RequireAppConfigurationItem: requireAppConfigurationItem, RequireAppADGroups: requireAppADGroups},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
},
Expand Down Expand Up @@ -112,7 +113,7 @@ func TestGetApplications_HasAccessToSomeRR(t *testing.T) {
NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, _ v1.RadixRegistration) (bool, error) {
return false, nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand All @@ -129,7 +130,7 @@ func TestGetApplications_HasAccessToSomeRR(t *testing.T) {
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient, certClient, NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, rr v1.RadixRegistration) (bool, error) {
return rr.GetName() == "my-second-app", nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand All @@ -146,7 +147,7 @@ func TestGetApplications_HasAccessToSomeRR(t *testing.T) {
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient, certClient, NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, _ v1.RadixRegistration) (bool, error) {
return true, nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand Down Expand Up @@ -227,7 +228,7 @@ func TestSearchApplicationsPost(t *testing.T) {
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient, certClient, NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, _ v1.RadixRegistration) (bool, error) {
return true, nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand Down Expand Up @@ -309,7 +310,7 @@ func TestSearchApplicationsPost(t *testing.T) {
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient, certClient, NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, _ v1.RadixRegistration) (bool, error) {
return false, nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand Down Expand Up @@ -405,7 +406,7 @@ func TestSearchApplicationsGet(t *testing.T) {
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient, certClient, NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, _ v1.RadixRegistration) (bool, error) {
return true, nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand Down Expand Up @@ -477,7 +478,7 @@ func TestSearchApplicationsGet(t *testing.T) {
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, kedaClient, secretproviderclient, certClient, NewApplicationController(
func(_ context.Context, _ kubernetes.Interface, _ v1.RadixRegistration) (bool, error) {
return false, nil
}, newTestApplicationHandlerFactory(ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: true},
}, newTestApplicationHandlerFactory(config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: true},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return true, nil
})))
Expand Down Expand Up @@ -1480,7 +1481,7 @@ func TestModifyApplication_UpdateADGroupValidation(t *testing.T) {
for _, ts := range scenarios {
t.Run(ts.name, func(t *testing.T) {
_, controllerTestUtils, _, radixClient, _, _, _, _ := setupTestWithFactory(t, newTestApplicationHandlerFactory(
ApplicationHandlerConfig{RequireAppConfigurationItem: true, RequireAppADGroups: ts.requireAppADGroups},
config.Config{RequireAppConfigurationItem: true, RequireAppADGroups: ts.requireAppADGroups},
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) {
return ts.hasAccessToAdGroups, nil
},
Expand Down Expand Up @@ -1970,11 +1971,11 @@ func buildApplicationRegistrationRequest(applicationRegistration applicationMode
}

type testApplicationHandlerFactory struct {
config ApplicationHandlerConfig
config config.Config
hasAccessToGetConfigMap hasAccessToGetConfigMapFunc
}

func newTestApplicationHandlerFactory(config ApplicationHandlerConfig, hasAccessToGetConfigMap hasAccessToGetConfigMapFunc) *testApplicationHandlerFactory {
func newTestApplicationHandlerFactory(config config.Config, hasAccessToGetConfigMap hasAccessToGetConfigMapFunc) *testApplicationHandlerFactory {
return &testApplicationHandlerFactory{
config: config,
hasAccessToGetConfigMap: hasAccessToGetConfigMap,
Expand Down
9 changes: 5 additions & 4 deletions api/applications/applications_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
jobModels "github.com/equinor/radix-api/api/jobs/models"
"github.com/equinor/radix-api/api/kubequery"
apimodels "github.com/equinor/radix-api/api/models"
"github.com/equinor/radix-api/internal/config"
"github.com/equinor/radix-api/models"
radixhttp "github.com/equinor/radix-common/net/http"
radixutils "github.com/equinor/radix-common/utils"
Expand Down Expand Up @@ -54,24 +55,24 @@ type ApplicationHandler struct {
jobHandler job.JobHandler
environmentHandler environments.EnvironmentHandler
accounts models.Accounts
config ApplicationHandlerConfig
config config.Config
namespace string
hasAccessToGetConfigMap func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error)
}

// NewApplicationHandler Constructor
func NewApplicationHandler(accounts models.Accounts, config ApplicationHandlerConfig, hasAccessToGetConfigMap hasAccessToGetConfigMapFunc) ApplicationHandler {
func NewApplicationHandler(accounts models.Accounts, config config.Config, hasAccessToGetConfigMap hasAccessToGetConfigMapFunc) ApplicationHandler {
return ApplicationHandler{
accounts: accounts,
jobHandler: job.Init(accounts, deployments.Init(accounts)),
jobHandler: job.Init(accounts, deployments.Init(accounts), config.PipelineImageTag, config.TektonImageTag),
environmentHandler: environments.Init(environments.WithAccounts(accounts)),
config: config,
namespace: getApiNamespace(config),
hasAccessToGetConfigMap: hasAccessToGetConfigMap,
}
}

func getApiNamespace(config ApplicationHandlerConfig) string {
func getApiNamespace(config config.Config) string {
if namespace := operatorUtils.GetEnvironmentNamespace(config.AppName, config.EnvironmentName); len(namespace) > 0 {
return namespace
}
Expand Down
46 changes: 0 additions & 46 deletions api/applications/applications_handler_config.go

This file was deleted.

5 changes: 3 additions & 2 deletions api/applications/applications_handler_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/equinor/radix-api/api/utils/access"
"github.com/equinor/radix-api/internal/config"
"github.com/equinor/radix-api/models"
authorizationapi "k8s.io/api/authorization/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -15,11 +16,11 @@ type ApplicationHandlerFactory interface {
}

type applicationHandlerFactory struct {
config ApplicationHandlerConfig
config config.Config
}

// NewApplicationHandlerFactory creates a new ApplicationHandlerFactory
func NewApplicationHandlerFactory(config ApplicationHandlerConfig) ApplicationHandlerFactory {
func NewApplicationHandlerFactory(config config.Config) ApplicationHandlerFactory {
return &applicationHandlerFactory{
config: config,
}
Expand Down
26 changes: 13 additions & 13 deletions api/jobs/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (jc *jobController) GetApplicationJobs(accounts models.Accounts, w http.Res
// description: "Not found"
appName := mux.Vars(r)["appName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
jobSummaries, err := handler.GetApplicationJobs(r.Context(), appName)

if err != nil {
Expand Down Expand Up @@ -168,7 +168,7 @@ func (jc *jobController) GetApplicationJob(accounts models.Accounts, w http.Resp
appName := mux.Vars(r)["appName"]
jobName := mux.Vars(r)["jobName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
jobDetail, err := handler.GetApplicationJob(r.Context(), appName, jobName)

if err != nil {
Expand Down Expand Up @@ -215,7 +215,7 @@ func (jc *jobController) StopApplicationJob(accounts models.Accounts, w http.Res
appName := mux.Vars(r)["appName"]
jobName := mux.Vars(r)["jobName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
err := handler.StopJob(r.Context(), appName, jobName)

if err != nil {
Expand Down Expand Up @@ -261,7 +261,7 @@ func (jc *jobController) RerunApplicationJob(accounts models.Accounts, w http.Re
// description: "Not found"
appName := mux.Vars(r)["appName"]
jobName := mux.Vars(r)["jobName"]
handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
err := handler.RerunJob(r.Context(), appName, jobName)

if err != nil {
Expand Down Expand Up @@ -312,7 +312,7 @@ func (jc *jobController) GetTektonPipelineRuns(accounts models.Accounts, w http.
appName := mux.Vars(r)["appName"]
jobName := mux.Vars(r)["jobName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
tektonPipelineRuns, err := handler.GetTektonPipelineRuns(r.Context(), appName, jobName)

if err != nil {
Expand Down Expand Up @@ -367,7 +367,7 @@ func (jc *jobController) GetTektonPipelineRun(accounts models.Accounts, w http.R
jobName := mux.Vars(r)["jobName"]
pipelineRunName := mux.Vars(r)["pipelineRunName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
tektonPipelineRun, err := handler.GetTektonPipelineRun(r.Context(), appName, jobName, pipelineRunName)

if err != nil {
Expand Down Expand Up @@ -424,7 +424,7 @@ func (jc *jobController) GetTektonPipelineRunTasks(accounts models.Accounts, w h
jobName := mux.Vars(r)["jobName"]
pipelineRunName := mux.Vars(r)["pipelineRunName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
tektonTasks, err := handler.GetTektonPipelineRunTasks(r.Context(), appName, jobName, pipelineRunName)

if err != nil {
Expand Down Expand Up @@ -485,7 +485,7 @@ func (jc *jobController) GetTektonPipelineRunTask(accounts models.Accounts, w ht
pipelineRunName := mux.Vars(r)["pipelineRunName"]
taskName := mux.Vars(r)["taskName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
tektonTasks, err := handler.GetTektonPipelineRunTask(r.Context(), appName, jobName, pipelineRunName, taskName)

if err != nil {
Expand Down Expand Up @@ -548,7 +548,7 @@ func (jc *jobController) GetTektonPipelineRunTaskSteps(accounts models.Accounts,
pipelineRunName := mux.Vars(r)["pipelineRunName"]
taskName := mux.Vars(r)["taskName"]

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
tektonTaskSteps, err := handler.GetTektonPipelineRunTaskSteps(r.Context(), appName, jobName, pipelineRunName, taskName)

if err != nil {
Expand Down Expand Up @@ -638,13 +638,13 @@ func (jc *jobController) GetTektonPipelineRunTaskStepLogs(accounts models.Accoun
return
}

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
log, err := handler.GetTektonPipelineRunTaskStepLogs(r.Context(), appName, jobName, pipelineRunName, taskName, stepName, &since, logLines)
if err != nil {
jc.ErrorResponse(w, r, err)
return
}
defer func() {_ = log.Close()}()
defer func() { _ = log.Close() }()

if asFile {
fileName := fmt.Sprintf("%s.log", time.Now().Format("20060102150405"))
Expand Down Expand Up @@ -721,13 +721,13 @@ func (jc *jobController) GetPipelineJobStepLogs(accounts models.Accounts, w http
return
}

handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")
log, err := handler.GetPipelineJobStepLogs(r.Context(), appName, jobName, stepName, &since, logLines)
if err != nil {
jc.ErrorResponse(w, r, err)
return
}
defer func() {_ = log.Close()}()
defer func() { _ = log.Close() }()

if asFile {
fileName := fmt.Sprintf("%s.log", time.Now().Format("20060102150405"))
Expand Down
2 changes: 1 addition & 1 deletion api/jobs/job_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGetApplicationJob(t *testing.T) {
}

accounts := models.NewAccounts(client, radixclient, kedaClient, secretproviderclient, nil, certClient, client, radixclient, kedaClient, secretproviderclient, nil, certClient, "", radixmodels.Impersonation{})
handler := Init(accounts, deployments.Init(accounts))
handler := Init(accounts, deployments.Init(accounts), "", "")

anyPipeline, _ := pipeline.GetPipelineFromName(anyPipelineName)
jobSummary, _ := handler.HandleStartPipelineJob(context.Background(), anyAppName, anyPipeline, jobParameters)
Expand Down
22 changes: 13 additions & 9 deletions api/jobs/job_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ const (

// JobHandler Instance variables
type JobHandler struct {
accounts models.Accounts
userAccount models.Account
serviceAccount models.Account
deploy deployments.DeployHandler
accounts models.Accounts
userAccount models.Account
serviceAccount models.Account
deploy deployments.DeployHandler
pipelineImageTag string
tektonImageTag string
}

// Init Constructor
func Init(accounts models.Accounts, deployHandler deployments.DeployHandler) JobHandler {
func Init(accounts models.Accounts, deployHandler deployments.DeployHandler, pipelineImageTag, tektonImageTag string) JobHandler {
return JobHandler{
accounts: accounts,
userAccount: accounts.UserAccount,
serviceAccount: accounts.ServiceAccount,
deploy: deployHandler,
accounts: accounts,
userAccount: accounts.UserAccount,
serviceAccount: accounts.ServiceAccount,
deploy: deployHandler,
pipelineImageTag: pipelineImageTag,
tektonImageTag: tektonImageTag,
}
}

Expand Down
Loading

0 comments on commit 2538465

Please sign in to comment.