UNCLASSIFIED

Commit 09ef6eeb authored by Jason van Brackel's avatar Jason van Brackel
Browse files

feat: Add CI Config file to project reconciler

parent 19224546
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"strconv" "strconv"
"time" "time"
apisGitlab "valkyrie.dso.mil/valkyrie-api/apis/gitlab" apisGitLab "valkyrie.dso.mil/valkyrie-api/apis/gitlab"
gitlabv1alpha1 "valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1" gitlabv1alpha1 "valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1"
gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab" gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab"
) )
...@@ -37,18 +37,18 @@ import ( ...@@ -37,18 +37,18 @@ import (
const ( const (
errorUnableToFetchGroup = "unable to fetch group" errorUnableToFetchGroup = "unable to fetch group"
errorWhileSearchingGroups = "Error while searching groups" errorWhileSearchingGroups = "Error while searching groups"
errorWhileCreatingGitlabGroup = "Error while creating GitLab group" errorWhileCreatingGitLabGroup = "Error while creating GitLab group"
errorWhileUpdatingGitlabGroup = "Error while updating GitLab group" errorWhileUpdatingGitLabGroup = "Error while updating GitLab group"
errorUnableToUpdateStatus = "Unable to update status" errorUnableToUpdateStatus = "Unable to update status"
errorUnableToProcessProjects = "Unable to process projects" errorUnableToProcessProjects = "Unable to process projects"
errorTryingToCreateProject = "Error trying to create project" errorTryingToCreateProject = "Error trying to create project"
errorLookingUpProject = "Error looking up project" errorLookingUpProject = "Error looking up project"
errorUpdatingProject = "Error updating project" errorUpdatingProject = "Error updating project"
errorUnableToSetupGitlabClient = "Error unable to setup Gitlab client" errorUnableToSetupGitLabClient = "Error unable to setup GitLab client"
errorWhileUpdatingGitlabGroupCiVariables = "Error updating the Gitlab group CI variables" errorWhileUpdatingGitLabGroupCiVariables = "Error updating the GitLab group CI variables"
errorGettingGroupVariablesFromGitlab = "Error getting group variables from Gitlab" errorGettingGroupVariablesFromGitLab = "Error getting group variables from GitLab"
errorCreatingGroupVariableInGitlab = "Error creating group variable in Gitlab" errorCreatingGroupVariableInGitLab = "Error creating group variable in GitLab"
errorUpdatingGroupVariableInGitLab = "Error updating group variable in Gitlab" errorUpdatingGroupVariableInGitLab = "Error updating group variable in GitLab"
) )
// Group Status // Group Status
...@@ -66,14 +66,14 @@ const ( ...@@ -66,14 +66,14 @@ const (
const valkyrie = "valkyrie" const valkyrie = "valkyrie"
// GroupReconciler reconciles the state of a Gitlab Group, for each reconciliation loop it will log in to Gitlab // GroupReconciler reconciles the state of a GitLab Group, for each reconciliation loop it will log in to GitLab
// with credentials in the secret provided. It will then check the state of the Group, and create it if necessary. // with credentials in the secret provided. It will then check the state of the Group, and create it if necessary.
type GroupReconciler struct { type GroupReconciler struct {
client.Client client.Client
Log logr.Logger Log logr.Logger
Scheme *runtime.Scheme Scheme *runtime.Scheme
gitlabClient gitlabClient.Client gitlabClient gitlabClient.Client
gitlabClientConfiguration apisGitlab.ClientConfiguration gitlabClientConfiguration apisGitLab.ClientConfiguration
} }
//+kubebuilder:rbac:groups=gitlab.valkyrie.dso.mil,resources=groups,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=gitlab.valkyrie.dso.mil,resources=groups,verbs=get;list;watch;create;update;patch;delete
...@@ -86,7 +86,7 @@ type GroupReconciler struct { ...@@ -86,7 +86,7 @@ type GroupReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to // Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state. // move the current state of the cluster closer to the desired state.
// The reconcile loop for the Gitlab Group will update the Group and any of the child Project API Objects. // The reconcile loop for the GitLab Group will update the Group and any of the child Project API Objects.
func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Log = r.Log.WithValues("group", req.NamespacedName) r.Log = r.Log.WithValues("group", req.NamespacedName)
...@@ -105,14 +105,14 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl ...@@ -105,14 +105,14 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
// Do a nil check here so we can use mock gitlabClients // Do a nil check here so we can use mock gitlabClients
if r.gitlabClient == nil { if r.gitlabClient == nil {
if r.gitlabClientConfiguration == nil { if r.gitlabClientConfiguration == nil {
r.gitlabClientConfiguration = apisGitlab.ClientConfigurationImpl{ r.gitlabClientConfiguration = apisGitLab.ClientConfigurationImpl{
Log: r.Log, Log: r.Log,
Ctx: ctx, Ctx: ctx,
Req: req, Req: req,
} }
} }
if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, group.Spec.GitlabCredentialsName); err != nil { if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, group.Spec.GitLabCredentialsName); err != nil {
r.Log.Error(err, errorUnableToSetupGitlabClient) r.Log.Error(err, errorUnableToSetupGitLabClient)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
} }
...@@ -127,18 +127,18 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl ...@@ -127,18 +127,18 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
if !found { if !found {
if gitlabGroup, _, err = r.createGroup(group); err != nil { if gitlabGroup, _, err = r.createGroup(group); err != nil {
r.Log.Error(err, errorWhileCreatingGitlabGroup, "group", group) r.Log.Error(err, errorWhileCreatingGitLabGroup, "group", group)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
} else { } else {
if gitlabGroup, _, err = r.updateGroup(group); err != nil { if gitlabGroup, _, err = r.updateGroup(group); err != nil {
r.Log.Error(err, errorWhileUpdatingGitlabGroup, "group", group) r.Log.Error(err, errorWhileUpdatingGitLabGroup, "group", group)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
} }
if err = r.updateCiVariables(gitlabGroup.ID, group); err != nil { if err = r.updateCiVariables(gitlabGroup.ID, group); err != nil {
r.Log.Error(err, errorWhileUpdatingGitlabGroupCiVariables, "group", group) r.Log.Error(err, errorWhileUpdatingGitLabGroupCiVariables, "group", group)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
...@@ -317,11 +317,11 @@ func (r *GroupReconciler) updateCiVariables(ID int, group *gitlabv1alpha1.Group) ...@@ -317,11 +317,11 @@ func (r *GroupReconciler) updateCiVariables(ID int, group *gitlabv1alpha1.Group)
for _, variableToUpdate := range variablesToUpdate { for _, variableToUpdate := range variablesToUpdate {
if groupVariable, statusCode, err = r.gitlabClient.GetGroupVariable(ID, variableToUpdate); err != nil { if groupVariable, statusCode, err = r.gitlabClient.GetGroupVariable(ID, variableToUpdate); err != nil {
if statusCode != 404 { if statusCode != 404 {
r.Log.Error(err, errorGettingGroupVariablesFromGitlab, "statusCode", statusCode, "variable", variablesToUpdate) r.Log.Error(err, errorGettingGroupVariablesFromGitLab, "statusCode", statusCode, "variable", variablesToUpdate)
return err return err
} }
if groupVariable, statusCode, err = r.CreateCiVariable(ID, variableToUpdate, group); err != nil { if groupVariable, statusCode, err = r.CreateCiVariable(ID, variableToUpdate, group); err != nil {
r.Log.Error(err, errorCreatingGroupVariableInGitlab, "statusCode", statusCode, "variable", variablesToUpdate) r.Log.Error(err, errorCreatingGroupVariableInGitLab, "statusCode", statusCode, "variable", variablesToUpdate)
return err return err
} }
} else { } else {
......
...@@ -42,7 +42,7 @@ func getGreenGroup() *gitlabv1alpha1.Group { ...@@ -42,7 +42,7 @@ func getGreenGroup() *gitlabv1alpha1.Group {
FullPath: "/greenGroup", FullPath: "/greenGroup",
Name: "greenGroup", Name: "greenGroup",
Description: "a green Group", Description: "a green Group",
GitlabCredentialsName: "greenCredentialsName", GitLabCredentialsName: "greenCredentialsName",
KustomizeProductionPath: "/kustomize/prod/path", KustomizeProductionPath: "/kustomize/prod/path",
KustomizeStagingPath: "/kustomize/staging/path", KustomizeStagingPath: "/kustomize/staging/path",
ManifestRepositoryURL: "https://gitserver/manifest/repo/url", ManifestRepositoryURL: "https://gitserver/manifest/repo/url",
...@@ -62,7 +62,7 @@ func getGreenGroup() *gitlabv1alpha1.Group { ...@@ -62,7 +62,7 @@ func getGreenGroup() *gitlabv1alpha1.Group {
GroupID: greenGroupID, GroupID: greenGroupID,
Name: "A Green Project", Name: "A Green Project",
FullPath: "/greenGroup/greenProject", FullPath: "/greenGroup/greenProject",
GitlabCredentialsName: "greenCredentialsName", GitLabCredentialsName: "greenCredentialsName",
ImpactLevel: "2", ImpactLevel: "2",
StorageTypes: nil, StorageTypes: nil,
VirtualService: "", VirtualService: "",
...@@ -74,7 +74,7 @@ func getGreenGroup() *gitlabv1alpha1.Group { ...@@ -74,7 +74,7 @@ func getGreenGroup() *gitlabv1alpha1.Group {
return returnGroup return returnGroup
} }
func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogger, *MockClientConfiguration, *MockClient, *MockGitlabClient) { func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogger, *MockClientConfiguration, *MockClient, *MockGitLabClient) {
builder := gitlabv1alpha1.SchemeBuilder.Register(&gitlabv1alpha1.Group{}, &gitlabv1alpha1.GroupList{}) builder := gitlabv1alpha1.SchemeBuilder.Register(&gitlabv1alpha1.Group{}, &gitlabv1alpha1.GroupList{})
scheme, _ := builder.Build() scheme, _ := builder.Build()
loggerMock := MockLogger{ loggerMock := MockLogger{
...@@ -91,10 +91,10 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge ...@@ -91,10 +91,10 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge
Name: greenGroupName, Name: greenGroupName,
}] = greenGroup }] = greenGroup
expectedGitlabGroups := make(map[int]*gitlab.Group) expectedGitLabGroups := make(map[int]*gitlab.Group)
expectedGitlabGroups[greenGroupID] = getGreenGitlabGroup() expectedGitLabGroups[greenGroupID] = getGreenGitLabGroup()
gitlabClientMock := MockGitlabClient{ gitlabClientMock := MockGitLabClient{
expectedGroups: expectedGitlabGroups, expectedGroups: expectedGitLabGroups,
} }
key := ManifestRepoURLVariableName key := ManifestRepoURLVariableName
...@@ -114,7 +114,7 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge ...@@ -114,7 +114,7 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge
gitlabClientMock.AddGroupVariable(greenGroupID, options) gitlabClientMock.AddGroupVariable(greenGroupID, options)
configurationMock := MockClientConfiguration{ configurationMock := MockClientConfiguration{
GitlabClient: &gitlabClientMock, GitLabClient: &gitlabClientMock,
SetupClientFunction: nil, SetupClientFunction: nil,
SetupClientCalled: false, SetupClientCalled: false,
} }
...@@ -127,7 +127,7 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge ...@@ -127,7 +127,7 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge
return &sut, &loggerMock, &configurationMock, &clientMock, &gitlabClientMock return &sut, &loggerMock, &configurationMock, &clientMock, &gitlabClientMock
} }
func getGreenGitlabGroup() *gitlab.Group { func getGreenGitLabGroup() *gitlab.Group {
return &gitlab.Group{ return &gitlab.Group{
ID: greenGroupID, ID: greenGroupID,
Path: "/aGreenGroup", Path: "/aGreenGroup",
...@@ -184,7 +184,7 @@ var _ = Describe("Reconcile", func() { ...@@ -184,7 +184,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest()) result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() { It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error")) Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorUnableToSetupGitlabClient)) Expect(logger.loggedMessage).To(Equal(errorUnableToSetupGitLabClient))
}) })
It("should return a reconcile result, and the error.", func() { It("should return a reconcile result, and the error.", func() {
Expect(result).To(Equal(ctrl.Result{ Expect(result).To(Equal(ctrl.Result{
...@@ -196,7 +196,7 @@ var _ = Describe("Reconcile", func() { ...@@ -196,7 +196,7 @@ var _ = Describe("Reconcile", func() {
Context("groupExists fails", func() { Context("groupExists fails", func() {
sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState() sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState()
sut.gitlabClient = &MockGitlabClient{ sut.gitlabClient = &MockGitLabClient{
newClientFunction: func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) { newClientFunction: func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) {
return &gitlab.Client{}, nil return &gitlab.Client{}, nil
}, },
...@@ -221,7 +221,7 @@ var _ = Describe("Reconcile", func() { ...@@ -221,7 +221,7 @@ var _ = Describe("Reconcile", func() {
Context("createGroup fails", func() { Context("createGroup fails", func() {
sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState() sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState()
sut.gitlabClient = &MockGitlabClient{ sut.gitlabClient = &MockGitLabClient{
newClientFunction: func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) { newClientFunction: func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) {
return &gitlab.Client{}, nil return &gitlab.Client{}, nil
}, },
...@@ -241,7 +241,7 @@ var _ = Describe("Reconcile", func() { ...@@ -241,7 +241,7 @@ var _ = Describe("Reconcile", func() {
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error")) Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorWhileCreatingGitlabGroup)) Expect(logger.loggedMessage).To(Equal(errorWhileCreatingGitLabGroup))
}) })
It("should return an error", func() { It("should return an error", func() {
Expect(err).NotTo(BeNil()) Expect(err).NotTo(BeNil())
...@@ -262,7 +262,7 @@ var _ = Describe("Reconcile", func() { ...@@ -262,7 +262,7 @@ var _ = Describe("Reconcile", func() {
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error")) Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroup)) Expect(logger.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroup))
}) })
It("should return an error", func() { It("should return an error", func() {
Expect(err).NotTo(BeNil()) Expect(err).NotTo(BeNil())
...@@ -276,7 +276,7 @@ var _ = Describe("Reconcile", func() { ...@@ -276,7 +276,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest()) result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroupCiVariables)) Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroupCiVariables))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
...@@ -293,7 +293,7 @@ var _ = Describe("Reconcile", func() { ...@@ -293,7 +293,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest()) result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroupCiVariables)) Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroupCiVariables))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
...@@ -310,7 +310,7 @@ var _ = Describe("Reconcile", func() { ...@@ -310,7 +310,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest()) result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroupCiVariables)) Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroupCiVariables))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
......
...@@ -414,7 +414,7 @@ func (m *MockError) Error() string { ...@@ -414,7 +414,7 @@ func (m *MockError) Error() string {
return m.message return m.message
} }
type MockGitlabClient struct { type MockGitLabClient struct {
newClientFunction func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) newClientFunction func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error)
getGroupsFunction func(name *string) ([]*gitlab.Group, int, error) getGroupsFunction func(name *string) ([]*gitlab.Group, int, error)
getGroupVariableFunction func(groupID int, key string) (*gitlab.GroupVariable, int, error) getGroupVariableFunction func(groupID int, key string) (*gitlab.GroupVariable, int, error)
...@@ -439,7 +439,7 @@ type MockGitlabClient struct { ...@@ -439,7 +439,7 @@ type MockGitlabClient struct {
getProjectVariableFunction func(projectID int, key string) (*gitlab.ProjectVariable, int, error) getProjectVariableFunction func(projectID int, key string) (*gitlab.ProjectVariable, int, error)
} }
func (m *MockGitlabClient) GetGroupVariable(groupID int, key string) (*gitlab.GroupVariable, int, error) { func (m *MockGitLabClient) GetGroupVariable(groupID int, key string) (*gitlab.GroupVariable, int, error) {
if m.getGroupVariableFunction != nil { if m.getGroupVariableFunction != nil {
return m.getGroupVariableFunction(groupID, key) return m.getGroupVariableFunction(groupID, key)
} }
...@@ -457,7 +457,7 @@ func (m *MockGitlabClient) GetGroupVariable(groupID int, key string) (*gitlab.Gr ...@@ -457,7 +457,7 @@ func (m *MockGitlabClient) GetGroupVariable(groupID int, key string) (*gitlab.Gr
return m.expectedGroupVariables[key], 200, nil return m.expectedGroupVariables[key], 200, nil
} }
func (m *MockGitlabClient) GetGroupVariables(groupID int) ([]*gitlab.GroupVariable, int, error) { func (m *MockGitLabClient) GetGroupVariables(groupID int) ([]*gitlab.GroupVariable, int, error) {
if m.expectedGroupVariables == nil { if m.expectedGroupVariables == nil {
m.expectedGroupVariables = make(map[string]*gitlab.GroupVariable) m.expectedGroupVariables = make(map[string]*gitlab.GroupVariable)
} }
...@@ -471,7 +471,7 @@ func (m *MockGitlabClient) GetGroupVariables(groupID int) ([]*gitlab.GroupVariab ...@@ -471,7 +471,7 @@ func (m *MockGitlabClient) GetGroupVariables(groupID int) ([]*gitlab.GroupVariab
return returnVariables, 200, nil return returnVariables, 200, nil
} }
func (m *MockGitlabClient) GetProjectVariables(projectID int) ([]*gitlab.ProjectVariable, int, error) { func (m *MockGitLabClient) GetProjectVariables(projectID int) ([]*gitlab.ProjectVariable, int, error) {
if m.expectedProjectVariables == nil { if m.expectedProjectVariables == nil {
m.expectedProjectVariables = make(map[string]*gitlab.ProjectVariable) m.expectedProjectVariables = make(map[string]*gitlab.ProjectVariable)
} }
...@@ -485,7 +485,7 @@ func (m *MockGitlabClient) GetProjectVariables(projectID int) ([]*gitlab.Project ...@@ -485,7 +485,7 @@ func (m *MockGitlabClient) GetProjectVariables(projectID int) ([]*gitlab.Project
return returnVariables, 200, nil return returnVariables, 200, nil
} }
func (m *MockGitlabClient) GetProjectVariable(projectID int, key string) (*gitlab.ProjectVariable, int, error) { func (m *MockGitLabClient) GetProjectVariable(projectID int, key string) (*gitlab.ProjectVariable, int, error) {
if m.getProjectVariableFunction != nil { if m.getProjectVariableFunction != nil {
return m.getProjectVariableFunction(projectID, key) return m.getProjectVariableFunction(projectID, key)
} }
...@@ -502,7 +502,7 @@ func (m *MockGitlabClient) GetProjectVariable(projectID int, key string) (*gitla ...@@ -502,7 +502,7 @@ func (m *MockGitlabClient) GetProjectVariable(projectID int, key string) (*gitla
return m.expectedProjectVariables[key], 200, nil return m.expectedProjectVariables[key], 200, nil
} }
func (m *MockGitlabClient) AddGroupVariable(groupID int, options gitlab.CreateGroupVariableOptions) (*gitlab.GroupVariable, int, error) { func (m *MockGitLabClient) AddGroupVariable(groupID int, options gitlab.CreateGroupVariableOptions) (*gitlab.GroupVariable, int, error) {
if m.addGroupVariableFunction != nil { if m.addGroupVariableFunction != nil {
return m.addGroupVariableFunction(groupID, options) return m.addGroupVariableFunction(groupID, options)
} }
...@@ -525,7 +525,7 @@ func (m *MockGitlabClient) AddGroupVariable(groupID int, options gitlab.CreateGr ...@@ -525,7 +525,7 @@ func (m *MockGitlabClient) AddGroupVariable(groupID int, options gitlab.CreateGr
return &returnVariable, 200, nil return &returnVariable, 200, nil
} }
func (m *MockGitlabClient) UpdateGroupVariable(groupID int, key string, options gitlab.UpdateGroupVariableOptions) (*gitlab.GroupVariable, int, error) { func (m *MockGitLabClient) UpdateGroupVariable(groupID int, key string, options gitlab.UpdateGroupVariableOptions) (*gitlab.GroupVariable, int, error) {
if m.updateGroupVariableFunction != nil { if m.updateGroupVariableFunction != nil {
return m.updateGroupVariableFunction(groupID, key, options) return m.updateGroupVariableFunction(groupID, key, options)
} }
...@@ -547,7 +547,7 @@ func (m *MockGitlabClient) UpdateGroupVariable(groupID int, key string, options ...@@ -547,7 +547,7 @@ func (m *MockGitlabClient) UpdateGroupVariable(groupID int, key string, options
return &returnVariable, 200, nil return &returnVariable, 200, nil
} }
func (m *MockGitlabClient) DeleteGroupVariable(groupID int, key string, waitInterval int, waitCount int) (int, error) { func (m *MockGitLabClient) DeleteGroupVariable(groupID int, key string, waitInterval int, waitCount int) (int, error) {
if m.expectedGroupVariables == nil { if m.expectedGroupVariables == nil {
m.expectedGroupVariables = make(map[string]*gitlab.GroupVariable) m.expectedGroupVariables = make(map[string]*gitlab.GroupVariable)
} }
...@@ -561,7 +561,7 @@ func (m *MockGitlabClient) DeleteGroupVariable(groupID int, key string, waitInte ...@@ -561,7 +561,7 @@ func (m *MockGitlabClient) DeleteGroupVariable(groupID int, key string, waitInte
return 200, nil return 200, nil
} }
func (m *MockGitlabClient) AddProjectVariable(projectID int, options gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) { func (m *MockGitLabClient) AddProjectVariable(projectID int, options gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) {
if m.addProjectVariableFunction != nil { if m.addProjectVariableFunction != nil {
return m.addProjectVariableFunction(projectID, options) return m.addProjectVariableFunction(projectID, options)
} }
...@@ -583,7 +583,7 @@ func (m *MockGitlabClient) AddProjectVariable(projectID int, options gitlab.Crea ...@@ -583,7 +583,7 @@ func (m *MockGitlabClient) AddProjectVariable(projectID int, options gitlab.Crea
return &returnVariable, 200, nil return &returnVariable, 200, nil
} }
func (m *MockGitlabClient) UpdateProjectVariable(projectID int, key string, options gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) { func (m *MockGitLabClient) UpdateProjectVariable(projectID int, key string, options gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) {
if m.updateProjectVariableFunction != nil { if m.updateProjectVariableFunction != nil {
return m.updateProjectVariableFunction(projectID, key, options) return m.updateProjectVariableFunction(projectID, key, options)
} }
...@@ -605,7 +605,7 @@ func (m *MockGitlabClient) UpdateProjectVariable(projectID int, key string, opti ...@@ -605,7 +605,7 @@ func (m *MockGitlabClient) UpdateProjectVariable(projectID int, key string, opti
return &returnVariable, 200, nil return &returnVariable, 200, nil
} }
func (m *MockGitlabClient) DeleteProjectVariable(projectID int, key string, waitInterval int, waitCount int) (int, error) { func (m *MockGitLabClient) DeleteProjectVariable(projectID int, key string, waitInterval int, waitCount int) (int, error) {
if m.expectedProjectVariables == nil { if m.expectedProjectVariables == nil {
m.expectedProjectVariables = make(map[string]*gitlab.ProjectVariable) m.expectedProjectVariables = make(map[string]*gitlab.ProjectVariable)
} }
...@@ -619,39 +619,39 @@ func (m *MockGitlabClient) DeleteProjectVariable(projectID int, key string, wait ...@@ -619,39 +619,39 @@ func (m *MockGitlabClient) DeleteProjectVariable(projectID int, key string, wait
return 200, nil return 200, nil
} }
func (m *MockGitlabClient) GetUser(userID int) (*gitlab.User, int, error) { func (m *MockGitLabClient) GetUser(userID int) (*gitlab.User, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetUsers(search *string) ([]*gitlab.User, error) { func (m *MockGitLabClient) GetUsers(search *string) ([]*gitlab.User, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetUserByUsername(username *string) (*gitlab.User, int, error) { func (m *MockGitLabClient) GetUserByUsername(username *string) (*gitlab.User, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) AddUser(createUserOptions *gitlab.CreateUserOptions) (*gitlab.User, int, error) { func (m *MockGitLabClient) AddUser(createUserOptions *gitlab.CreateUserOptions) (*gitlab.User, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) UpdateUser(userID int, modifyUserOptions *gitlab.ModifyUserOptions) (*gitlab.User, int, error) { func (m *MockGitLabClient) UpdateUser(userID int, modifyUserOptions *gitlab.ModifyUserOptions) (*gitlab.User, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) DeleteUser(userID int, waitInterval int, waitCount int) (int, error) { func (m *MockGitLabClient) DeleteUser(userID int, waitInterval int, waitCount int) (int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) DeleteUserByUsername(username string, waitInterval int, waitCount int) (int, error) { func (m *MockGitLabClient) DeleteUserByUsername(username string, waitInterval int, waitCount int) (int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetGroupByFullPath(fullPath *string) (*gitlab.Group, int, error) { func (m *MockGitLabClient) GetGroupByFullPath(fullPath *string) (*gitlab.Group, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetGroups(search *string) ([]*gitlab.Group, error) { func (m *MockGitLabClient) GetGroups(search *string) ([]*gitlab.Group, error) {
if m.getGroupsFunction == nil { if m.getGroupsFunction == nil {
if m.expectedGroups == nil { if m.expectedGroups == nil {
return make([]*gitlab.Group, 0), nil return make([]*gitlab.Group, 0), nil
...@@ -677,15 +677,15 @@ func (m *MockGitlabClient) GetGroups(search *string) ([]*gitlab.Group, error) { ...@@ -677,15 +677,15 @@ func (m *MockGitlabClient) GetGroups(search *string) ([]*gitlab.Group, error) {
return groups, err return groups, err
} }
func (m *MockGitlabClient) AddGroupMember(groupID *int, userID *int, accessLevel gitlab.AccessLevelValue) (*gitlab.GroupMember, int, error) { func (m *MockGitLabClient) AddGroupMember(groupID *int, userID *int, accessLevel gitlab.AccessLevelValue) (*gitlab.GroupMember, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) DeleteGroup(groupID int, waitInterval int, waitCount int) (int, error) { func (m *MockGitLabClient) DeleteGroup(groupID int, waitInterval int, waitCount int) (int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetProject(projectID int) (*gitlab.Project, int, error) { func (m *MockGitLabClient) GetProject(projectID int) (*gitlab.Project, int, error) {
var returnProject *gitlab.Project var returnProject *gitlab.Project
var statusCode int var statusCode int
var err error var err error
...@@ -708,15 +708,15 @@ func (m *MockGitlabClient) GetProject(projectID int) (*gitlab.Project, int, erro ...@@ -708,15 +708,15 @@ func (m *MockGitlabClient) GetProject(projectID int) (*gitlab.Project, int, erro
return m.expectedProjects[projectID], statusCode, err return m.expectedProjects[projectID], statusCode, err
} }
func (m *MockGitlabClient) GetProjectByFullPath(fullPath *string) (*gitlab.Project, int, error) { func (m *MockGitLabClient) GetProjectByFullPath(fullPath *string) (*gitlab.Project, int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetProjects(search *string) ([]*gitlab.Project, error) { func (m *MockGitLabClient) GetProjects(search *string) ([]*gitlab.Project, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) AddProject(createProjectOptions gitlab.CreateProjectOptions) (*gitlab.Project, int, error) { func (m *MockGitLabClient) AddProject(createProjectOptions gitlab.CreateProjectOptions) (*gitlab.Project, int, error) {
if m.addProjectFunction != nil { if m.addProjectFunction != nil {
return m.addProjectFunction(createProjectOptions) return m.addProjectFunction(createProjectOptions)
} }
...@@ -733,7 +733,7 @@ func (m *MockGitlabClient) AddProject(createProjectOptions gitlab.CreateProjectO ...@@ -733,7 +733,7 @@ func (m *MockGitlabClient) AddProject(createProjectOptions gitlab.CreateProjectO
return m.expectedProjects[1], 200, nil return m.expectedProjects[1], 200, nil
} }
func (m *MockGitlabClient) UpdateProject(projectID int, editProjectOptions gitlab.EditProjectOptions) (*gitlab.Project, int, error) { func (m *MockGitLabClient) UpdateProject(projectID int, editProjectOptions gitlab.EditProjectOptions) (*gitlab.Project, int, error) {
if m.updateProjectFunction != nil { if m.updateProjectFunction != nil {
return m.updateProjectFunction(projectID, editProjectOptions) return m.updateProjectFunction(projectID, editProjectOptions)
} }
...@@ -750,43 +750,43 @@ func (m *MockGitlabClient) UpdateProject(projectID int, editProjectOptions gitla ...@@ -750,43 +750,43 @@ func (m *MockGitlabClient) UpdateProject(projectID int, editProjectOptions gitla
return m.expectedProjects[projectID], 200, nil return m.expectedProjects[projectID], 200, nil
} }
func (m *MockGitlabClient) DeleteProject(projectID int, waitInterval int, waitCount int) (int, error) { func (m *MockGitLabClient) DeleteProject(projectID int, waitInterval int, waitCount int) (int, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) GetMergeRequestByID(projectID int, mergeRequestID int) (*gitlab.MergeRequest, error) { func (m *MockGitLabClient) GetMergeRequestByID(projectID int, mergeRequestID int) (*gitlab.MergeRequest, error) {
if m.getMRByIDFunc != nil { if m.getMRByIDFunc != nil {
return m.getMRByIDFunc(projectID, mergeRequestID) return m.getMRByIDFunc(projectID, mergeRequestID)
} }
return nil, nil return nil, nil
} }
func (m *MockGitlabClient) GetMergeRequests(projectID int, sourceBranch string, targetBranch string) ([]*gitlab.MergeRequest, error) { func (m *MockGitLabClient) GetMergeRequests(projectID int, sourceBranch string, targetBranch string) ([]*gitlab.MergeRequest, error) {
if m.getMRsFunc != nil { if m.getMRsFunc != nil {
return m.getMRsFunc(projectID, sourceBranch, targetBranch) return m.getMRsFunc(projectID, sourceBranch, targetBranch)
} }
return nil, nil return nil, nil
} }
func (m *MockGitlabClient) CreateMergeRequest(projectID int, mrOptions *gitlab.CreateMergeRequestOptions) (*gitlab.MergeRequest, error) { func (m *MockGitLabClient) CreateMergeRequest(projectID int, mrOptions *gitlab.CreateMergeRequestOptions) (*gitlab.MergeRequest, error) {
if m.createMRFunc != nil { if m.createMRFunc != nil {
return m.createMRFunc(projectID, mrOptions) return m.createMRFunc(projectID, mrOptions)
} }
return nil, nil return nil, nil
} }
func (m *MockGitlabClient) UpdateMergeRequest(projectID int, mergeRequestID int, updateOptions *gitlab.UpdateMergeRequestOptions) (*gitlab.MergeRequest, error) { func (m *MockGitLabClient) UpdateMergeRequest(projectID int, mergeRequestID int, updateOptions *gitlab.UpdateMergeRequestOptions) (*gitlab.MergeRequest, error) {
panic("implement me") panic("implement me")
} }
func (m *MockGitlabClient) CloseMergeRequest(projectID int, mergeRequestID int) error { func (m *MockGitLabClient) CloseMergeRequest(projectID int, mergeRequestID int) error {
if m.closeMRFunc != nil { if m.closeMRFunc != nil {
return m.closeMRFunc(projectID, mergeRequestID) return m.closeMRFunc(projectID, mergeRequestID)
} }
return nil return nil
} }
func (m *MockGitlabClient) GetGroup(groupID int) (*gitlab.Group, int, error) { func (m *MockGitLabClient) GetGroup(groupID int) (*gitlab.Group, int, error) {
if m.getGroupFunction != nil { if m.getGroupFunction != nil {
return m.getGroupFunction(groupID) return m.getGroupFunction(groupID)
} }
...@@ -798,7 +798,7 @@ func (m *MockGitlabClient) GetGroup(groupID int) (*gitlab.Group, int, error) { ...@@ -798,7 +798,7 @@ func (m *MockGitlabClient) GetGroup(groupID int) (*gitlab.Group, int, error) {
return m.expectedGroups[groupID], 0, nil return m.expectedGroups[groupID], 0, nil
} }
func (m *MockGitlabClient) AddGroup(options gitlab.CreateGroupOptions) (*gitlab.Group, int, error) { func (m *MockGitLabClient) AddGroup(options gitlab.CreateGroupOptions) (*gitlab.Group, int, error) {
if m.addGroupFunction == nil { if m.addGroupFunction == nil {
if m.expectedGroups == nil { if m.expectedGroups == nil {
m.expectedGroups = make(map[int]*gitlab.Group) m.expectedGroups = make(map[int]*gitlab.Group)
...@@ -813,7 +813,7 @@ func (m *MockGitlabClient) AddGroup(options gitlab.CreateGroupOptions) (*gitlab. ...@@ -813,7 +813,7 @@ func (m *MockGitlabClient) AddGroup(options gitlab.CreateGroupOptions) (*gitlab.
return m.addGroupFunction(options) return m.addGroupFunction(options)
} }
func (m *MockGitlabClient) UpdateGroup(id int, options *gitlab.UpdateGroupOptions) (*gitlab.Group, int, error) { func (m *MockGitLabClient) UpdateGroup(id int, options *gitlab.UpdateGroupOptions) (*gitlab.Group, int, error) {
if m.updateGroupFunction == nil { if m.updateGroupFunction == nil {
if m.expectedGroups == nil { if m.expectedGroups == nil {
m.expectedGroups = make(map[int]*gitlab.Group) m.expectedGroups = make(map[int]*gitlab.Group)
...@@ -878,7 +878,7 @@ func (m *MockRepoClient) DeleteRemoteBranch(branchName string) (err error) { ...@@ -878,7 +878,7 @@ func (m *MockRepoClient) DeleteRemoteBranch(branchName string) (err error) {
} }
type MockClientConfiguration struct { type MockClientConfiguration struct {
GitlabClient gitlabClient.Client GitLabClient gitlabClient.Client
SetupClientFunction func(client client.Client, credentialsName string) (gitlabClient.Client, error) SetupClientFunction func(client client.Client, credentialsName string) (gitlabClient.Client, error)
SetupClientCalled bool SetupClientCalled bool
} }
...@@ -887,10 +887,10 @@ func (m *MockClientConfiguration) SetupClient(client client.Client, credentialsN ...@@ -887,10 +887,10 @@ func (m *MockClientConfiguration) SetupClient(client client.Client, credentialsN
m.SetupClientCalled = true m.SetupClientCalled = true
if m.SetupClientFunction == nil { if m.SetupClientFunction == nil {
if m.GitlabClient == nil { if m.GitLabClient == nil {
return &MockGitlabClient{}, nil return &MockGitLabClient{}, nil
} }
return m.GitlabClient, nil return m.GitLabClient, nil
} }
return m.SetupClientFunction(client, credentialsName) return m.SetupClientFunction(client, credentialsName)
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime" ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"strconv" "strconv"
apisGitlab "valkyrie.dso.mil/valkyrie-api/apis/gitlab" apisGitLab "valkyrie.dso.mil/valkyrie-api/apis/gitlab"
"valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1" "valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1"
gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab" gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab"
) )
...@@ -35,7 +35,7 @@ type ProjectReconciler struct { ...@@ -35,7 +35,7 @@ type ProjectReconciler struct {
Log logr.Logger Log logr.Logger
Scheme *runtime.Scheme Scheme *runtime.Scheme
gitlabClient gitlabClient.Client gitlabClient gitlabClient.Client
gitlabClientConfiguration apisGitlab.ClientConfiguration gitlabClientConfiguration apisGitLab.ClientConfiguration
} }
//+kubebuilder:rbac:groups=gitlab.valkyrie.dso.mil,resources=projects,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=gitlab.valkyrie.dso.mil,resources=projects,verbs=get;list;watch;create;update;patch;delete
...@@ -45,21 +45,21 @@ type ProjectReconciler struct { ...@@ -45,21 +45,21 @@ type ProjectReconciler struct {
// errors // errors
const ( const (
errorWhileLookingUpProject = "error while looking up project." errorWhileLookingUpProject = "error while looking up project."
errorGettingGroupFromGitlab = "Error while getting Group from Gitlab." errorGettingGroupFromGitLab = "Error while getting Group from GitLab."
errorUpdatingStatusOfProject = "Error updating status of project." errorUpdatingStatusOfProject = "Error updating status of project."
errorGettingProjectFromGitlab = "Error getting project from Gitlab." errorGettingProjectFromGitLab = "Error getting project from GitLab."
errorCreatingGitlabProject = "Error creating Gitlab project." errorCreatingGitLabProject = "Error creating GitLab project."
errorUpdatingGitlabProject = "Error updating Gitlab project." errorUpdatingGitLabProject = "Error updating GitLab project."
errorUpdatingProjectIDAnnotation = "Error updating project ID annotation." errorUpdatingProjectIDAnnotation = "Error updating project ID annotation."
errorUpdatingProjectVariableInGitlab = "Error updating project variable in Gitlab" errorUpdatingProjectVariableInGitLab = "Error updating project variable in GitLab"
errorGettingProjectVariableFromGitlab = "Error getting project variable from Gitlab" errorGettingProjectVariableFromGitLab = "Error getting project variable from GitLab"
errorCreatingProjectVariableInGitlab = "Error creating project variable in Gitlab" errorCreatingProjectVariableInGitLab = "Error creating project variable in GitLab"
errorWhileUpdatingProjectVariableInGitlab = "Error while updating project variable in gitlab" errorWhileUpdatingProjectVariableInGitLab = "Error while updating project variable in gitlab"
) )
// statuses // statuses
const ( const (
groupDoesntExist string = "GitlabGroupDoesNotExist" groupDoesntExist string = "GitLabGroupDoesNotExist"
) )
// ManifestImageVariableName - // ManifestImageVariableName -
...@@ -67,21 +67,7 @@ const ManifestImageVariableName = "MANIFEST_IMAGE" ...@@ -67,21 +67,7 @@ const ManifestImageVariableName = "MANIFEST_IMAGE"
const annotationKeyID = "ID" const annotationKeyID = "ID"
// Setup General Pipelines // Reconcile is the main reconciliation loop that will create/edit/delete GitLab Projects.
// Enable Public Pipelines
// Enable Auto-cancel redundant pipelines
// Enable skip outdated deployment jobs
// Set CI/CD Configuration file to products/{group}/{project-path}-ci.yml@platform-one/devops/pipeline-products
// Setup Artifacts
// Enable keep artifacts from most recent successful jobs
// TODO Setup Variables (Group Controller & Group Object needs updated here)
// KUSTOMIZE_PRODUCTION_PATH
// KUSTOMIZE_STAGING_PATH
// MAINIFEST_REPO_PATH
// Reconcile is the main reconciliation loop that will create/edit/delete Gitlab Projects.
func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Log = r.Log.WithValues("project", req.NamespacedName) r.Log = r.Log.WithValues("project", req.NamespacedName)
...@@ -98,22 +84,22 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ...@@ -98,22 +84,22 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
// Do a nil check here so we can use mock gitlabClients // Do a nil check here so we can use mock gitlabClients
if r.gitlabClient == nil { if r.gitlabClient == nil {
if r.gitlabClientConfiguration == nil { if r.gitlabClientConfiguration == nil {
r.gitlabClientConfiguration = apisGitlab.ClientConfigurationImpl{ r.gitlabClientConfiguration = apisGitLab.ClientConfigurationImpl{
Log: r.Log, Log: r.Log,
Ctx: ctx, Ctx: ctx,
Req: req, Req: req,
} }
} }
if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, project.Spec.GitlabCredentialsName); err != nil { if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, project.Spec.GitLabCredentialsName); err != nil {
r.Log.Error(err, errorUnableToSetupGitlabClient) r.Log.Error(err, errorUnableToSetupGitLabClient)
_ = r.updateStatus(ctx, project, errorUnableToSetupGitlabClient) _ = r.updateStatus(ctx, project, errorUnableToSetupGitLabClient)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
} }
// Make Sure the Group Exists in GitLab // Make Sure the Group Exists in GitLab
if _, err = r.getGitlabGroup(ctx, project, req); err != nil { if _, err = r.getGitLabGroup(ctx, project, req); err != nil {
r.Log.Error(err, errorGettingGroupFromGitlab, "request", req) r.Log.Error(err, errorGettingGroupFromGitLab, "request", req)
_ = r.updateStatus(ctx, project, groupDoesntExist) _ = r.updateStatus(ctx, project, groupDoesntExist)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
...@@ -122,28 +108,28 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ...@@ -122,28 +108,28 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
var gitlabProject *gitlab.Project var gitlabProject *gitlab.Project
id, _ := strconv.Atoi(project.ObjectMeta.Annotations["ID"]) id, _ := strconv.Atoi(project.ObjectMeta.Annotations["ID"])
if gitlabProject, err = r.getGitlabProject(id); err != nil { if gitlabProject, err = r.getGitLabProject(id); err != nil {
r.Log.Error(err, errorGettingProjectFromGitlab) r.Log.Error(err, errorGettingProjectFromGitLab)
_ = r.updateStatus(ctx, project, errorGettingProjectFromGitlab) _ = r.updateStatus(ctx, project, errorGettingProjectFromGitLab)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
if gitlabProject == nil { if gitlabProject == nil {
if gitlabProject, err = r.createGitlabProject(project); err != nil { if gitlabProject, err = r.createGitLabProject(project); err != nil {
r.Log.Error(err, errorCreatingGitlabProject) r.Log.Error(err, errorCreatingGitLabProject)
_ = r.updateStatus(ctx, project, errorCreatingGitlabProject) _ = r.updateStatus(ctx, project, errorCreatingGitLabProject)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
} }
if gitlabProject, err = r.updateGitlabProject(id, project); err != nil { if gitlabProject, err = r.updateGitLabProject(id, project); err != nil {
r.Log.Error(err, errorUpdatingGitlabProject) r.Log.Error(err, errorUpdatingGitLabProject)
_ = r.updateStatus(ctx, project, errorUpdatingGitlabProject) _ = r.updateStatus(ctx, project, errorUpdatingGitLabProject)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
if _, err = r.updateManifestImageSetting(id, project.Spec.ManifestImage); err != nil { if _, err = r.updateManifestImageSetting(id, project.Spec.ManifestImage); err != nil {
r.Log.Error(err, errorUpdatingProjectVariableInGitlab) r.Log.Error(err, errorUpdatingProjectVariableInGitLab)
_ = r.updateStatus(ctx, project, errorUpdatingProjectVariableInGitlab) _ = r.updateStatus(ctx, project, errorUpdatingProjectVariableInGitLab)
return ctrl.Result{Requeue: true}, err return ctrl.Result{Requeue: true}, err
} }
...@@ -183,20 +169,20 @@ func (r *ProjectReconciler) getProject(ctx context.Context, request ctrl.Request ...@@ -183,20 +169,20 @@ func (r *ProjectReconciler) getProject(ctx context.Context, request ctrl.Request
return &project, nil return &project, nil
} }
func (r *ProjectReconciler) getGitlabGroup(ctx context.Context, project *v1alpha1.Project, req ctrl.Request) (*gitlab.Group, error) { func (r *ProjectReconciler) getGitLabGroup(ctx context.Context, project *v1alpha1.Project, req ctrl.Request) (*gitlab.Group, error) {
var gitlabGroup *gitlab.Group var gitlabGroup *gitlab.Group
var response int var response int
var err error var err error
if gitlabGroup, response, err = r.gitlabClient.GetGroup(project.Spec.GroupID); err != nil { if gitlabGroup, response, err = r.gitlabClient.GetGroup(project.Spec.GroupID); err != nil {
r.Log.Error(err, errorGettingGroupFromGitlab, "response", response, "groupID", project) r.Log.Error(err, errorGettingGroupFromGitLab, "response", response, "groupID", project)
return nil, err return nil, err
} }
return gitlabGroup, nil return gitlabGroup, nil
} }
func (r *ProjectReconciler) getGitlabProject(id int) (*gitlab.Project, error) { func (r *ProjectReconciler) getGitLabProject(id int) (*gitlab.Project, error) {
var project *gitlab.Project var project *gitlab.Project
var statusCode int var statusCode int
var err error var err error
...@@ -210,12 +196,13 @@ func (r *ProjectReconciler) getGitlabProject(id int) (*gitlab.Project, error) { ...@@ -210,12 +196,13 @@ func (r *ProjectReconciler) getGitlabProject(id int) (*gitlab.Project, error) {
return project, nil return project, nil
} }
func (r *ProjectReconciler) createGitlabProject(project *v1alpha1.Project) (*gitlab.Project, error) { func (r *ProjectReconciler) createGitLabProject(project *v1alpha1.Project) (*gitlab.Project, error) {
var gitLabProject *gitlab.Project var gitLabProject *gitlab.Project
var err error var err error
createProjectOptions := gitlab.CreateProjectOptions{ createProjectOptions := gitlab.CreateProjectOptions{
Name: &project.Spec.Name, Name: &project.Spec.Name,
Path: &project.Spec.FullPath, Path: &project.Spec.FullPath,
CIConfigPath: &project.Spec.CiConfigurationPath,
} }
if gitLabProject, _, err = r.gitlabClient.AddProject(createProjectOptions); err != nil { if gitLabProject, _, err = r.gitlabClient.AddProject(createProjectOptions); err != nil {
return nil, err return nil, err
...@@ -224,12 +211,13 @@ func (r *ProjectReconciler) createGitlabProject(project *v1alpha1.Project) (*git ...@@ -224,12 +211,13 @@ func (r *ProjectReconciler) createGitlabProject(project *v1alpha1.Project) (*git
return gitLabProject, nil return gitLabProject, nil
} }
func (r *ProjectReconciler) updateGitlabProject(id int, project *v1alpha1.Project) (*gitlab.Project, error) { func (r *ProjectReconciler) updateGitLabProject(id int, project *v1alpha1.Project) (*gitlab.Project, error) {
var gitLabProject *gitlab.Project var gitLabProject *gitlab.Project
var err error var err error
if gitLabProject, _, err = r.gitlabClient.UpdateProject(id, gitlab.EditProjectOptions{ if gitLabProject, _, err = r.gitlabClient.UpdateProject(id, gitlab.EditProjectOptions{
Name: &project.Spec.Name, Name: &project.Spec.Name,
Path: &project.Spec.FullPath, Path: &project.Spec.FullPath,
CIConfigPath: &project.Spec.CiConfigurationPath,
}); err != nil { }); err != nil {
return nil, err return nil, err
} }
...@@ -264,12 +252,12 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri ...@@ -264,12 +252,12 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri
Masked: &masked, Masked: &masked,
EnvironmentScope: &environmentScope, EnvironmentScope: &environmentScope,
}); err != nil { }); err != nil {
r.Log.Error(err, errorCreatingProjectVariableInGitlab, "statusCode", statusCode) r.Log.Error(err, errorCreatingProjectVariableInGitLab, "statusCode", statusCode)
return projectVariable, err return projectVariable, err
} }
return projectVariable, err return projectVariable, err
} }
r.Log.Error(err, errorGettingProjectVariableFromGitlab, "statusCode", statusCode) r.Log.Error(err, errorGettingProjectVariableFromGitLab, "statusCode", statusCode)
return projectVariable, err return projectVariable, err
} }
...@@ -282,7 +270,7 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri ...@@ -282,7 +270,7 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri
}) })
if err != nil { if err != nil {
r.Log.Error(err, errorWhileUpdatingProjectVariableInGitlab, "statusCode", statusCode) r.Log.Error(err, errorWhileUpdatingProjectVariableInGitLab, "statusCode", statusCode)
return projectVariable, err return projectVariable, err
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime" ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
apisGitlab "valkyrie.dso.mil/valkyrie-api/apis/gitlab" apisGitLab "valkyrie.dso.mil/valkyrie-api/apis/gitlab"
"valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1" "valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1"
gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab" gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab"
) )
...@@ -80,7 +80,7 @@ func getProjectControllerWithMocksInGreenTestState() (ProjectReconciler, *MockMa ...@@ -80,7 +80,7 @@ func getProjectControllerWithMocksInGreenTestState() (ProjectReconciler, *MockMa
builder: builder, builder: builder,
} }
gitlabClient := MockGitlabClient{} gitlabClient := MockGitLabClient{}
sut := ProjectReconciler{ sut := ProjectReconciler{
Client: &clientMock, Client: &clientMock,
...@@ -129,7 +129,7 @@ var _ = Describe("reconcile", func() { ...@@ -129,7 +129,7 @@ var _ = Describe("reconcile", func() {
sut.gitlabClientConfiguration = nil sut.gitlabClientConfiguration = nil
sut.Reconcile(context.TODO(), getGreenProjectRequest()) sut.Reconcile(context.TODO(), getGreenProjectRequest())
It("should use the default client configuration implementation", func() { It("should use the default client configuration implementation", func() {
Expect(sut.gitlabClientConfiguration).To(BeAssignableToTypeOf(apisGitlab.ClientConfigurationImpl{})) Expect(sut.gitlabClientConfiguration).To(BeAssignableToTypeOf(apisGitLab.ClientConfigurationImpl{}))
}) })
}) })
Context("SetupClient fails", func() { Context("SetupClient fails", func() {
...@@ -144,7 +144,7 @@ var _ = Describe("reconcile", func() { ...@@ -144,7 +144,7 @@ var _ = Describe("reconcile", func() {
result, err := sut.Reconcile(context.TODO(), request) result, err := sut.Reconcile(context.TODO(), request)
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorUnableToSetupGitlabClient)) Expect(log.loggedMessage).To(Equal(errorUnableToSetupGitLabClient))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
...@@ -195,31 +195,31 @@ var _ = Describe("reconcile", func() { ...@@ -195,31 +195,31 @@ var _ = Describe("reconcile", func() {
Expect(log.loggedMessage).To(Equal(errorWhileLookingUpProject)) Expect(log.loggedMessage).To(Equal(errorWhileLookingUpProject))
}) })
}) })
Context("getGitlabProject returns an error", func() { Context("getGitLabProject returns an error", func() {
failingGitlabClient := MockGitlabClient{ failingGitLabClient := MockGitLabClient{
getProjectFunction: func(groupID int) (*gitlab.Project, int, error) { getProjectFunction: func(groupID int) (*gitlab.Project, int, error) {
return nil, 500, &MockError{ return nil, 500, &MockError{
message: "failure in getGitlabProject", message: "failure in getGitLabProject",
} }
}, },
} }
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState() sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitlabClient sut.gitlabClient = &failingGitLabClient
request := getRequestWithDefaultNamespacedTestProject() request := getRequestWithDefaultNamespacedTestProject()
result, err := sut.Reconcile(context.TODO(), request) result, err := sut.Reconcile(context.TODO(), request)
It("should return an error", func() { It("should return an error", func() {
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorGettingProjectFromGitlab)) Expect(log.loggedMessage).To(Equal(errorGettingProjectFromGitLab))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
}) })
}) })
Context("createGitlabProject returns an error", func() { Context("createGitLabProject returns an error", func() {
failingGitlabClient := MockGitlabClient{ failingGitLabClient := MockGitLabClient{
addProjectFunction: func(options gitlab.CreateProjectOptions) (*gitlab.Project, int, error) { addProjectFunction: func(options gitlab.CreateProjectOptions) (*gitlab.Project, int, error) {
return nil, 500, &MockError{ return nil, 500, &MockError{
message: "failure in addProject", message: "failure in addProject",
...@@ -227,56 +227,56 @@ var _ = Describe("reconcile", func() { ...@@ -227,56 +227,56 @@ var _ = Describe("reconcile", func() {
}, },
} }
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState() sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitlabClient sut.gitlabClient = &failingGitLabClient
request := getRequestWithDefaultNamespacedTestProject() request := getRequestWithDefaultNamespacedTestProject()
result, err := sut.Reconcile(context.TODO(), request) result, err := sut.Reconcile(context.TODO(), request)
It("should return an error", func() { It("should return an error", func() {
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorCreatingGitlabProject)) Expect(log.loggedMessage).To(Equal(errorCreatingGitLabProject))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
}) })
}) })
Context("updateGitlabProject returns an error", func() { Context("updateGitLabProject returns an error", func() {
failingGitlabClient := MockGitlabClient{ failingGitLabClient := MockGitLabClient{
getProjectFunction: func(projectID int) (*gitlab.Project, int, error) { getProjectFunction: func(projectID int) (*gitlab.Project, int, error) {
return &gitlab.Project{}, 1, nil return &gitlab.Project{}, 1, nil
}, },
updateProjectFunction: func(int, gitlab.EditProjectOptions) (*gitlab.Project, int, error) { updateProjectFunction: func(int, gitlab.EditProjectOptions) (*gitlab.Project, int, error) {
return nil, 500, &MockError{ return nil, 500, &MockError{
message: "failure in updateGitlabProject", message: "failure in updateGitLabProject",
} }
}, },
} }
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState() sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitlabClient sut.gitlabClient = &failingGitLabClient
request := getRequestWithDefaultNamespacedTestProject() request := getRequestWithDefaultNamespacedTestProject()
result, err := sut.Reconcile(context.TODO(), request) result, err := sut.Reconcile(context.TODO(), request)
It("should return an error", func() { It("should return an error", func() {
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorUpdatingGitlabProject)) Expect(log.loggedMessage).To(Equal(errorUpdatingGitLabProject))
}) })
It("should requeue the object", func() { It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
}) })
}) })
Context("getGitlabGroup returns an error", func() { Context("getGitLabGroup returns an error", func() {
failingGitlabClient := MockGitlabClient{ failingGitLabClient := MockGitLabClient{
getGroupFunction: func(groupID int) (*gitlab.Group, int, error) { getGroupFunction: func(groupID int) (*gitlab.Group, int, error) {
return nil, 500, &MockError{ return nil, 500, &MockError{
message: "failure in getGitlabGroup", message: "failure in getGitLabGroup",
} }
}, },
} }
sut, _, log, status := getProjectControllerWithMocksInGreenTestState() sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitlabClient sut.gitlabClient = &failingGitLabClient
request := getGreenProjectRequest() request := getGreenProjectRequest()
...@@ -288,7 +288,7 @@ var _ = Describe("reconcile", func() { ...@@ -288,7 +288,7 @@ var _ = Describe("reconcile", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true})) Expect(result).To(Equal(ctrl.Result{Requeue: true}))
}) })
It("should log that there was an error while looking up the group in gitlab", func() { It("should log that there was an error while looking up the group in gitlab", func() {
Expect(log.loggedMessage).To(Equal(errorGettingGroupFromGitlab)) Expect(log.loggedMessage).To(Equal(errorGettingGroupFromGitLab))
}) })
It("should set the project status to GroupDoesntExist", func() { It("should set the project status to GroupDoesntExist", func() {
Expect(status.updateFunctionCalled).To(BeTrue()) Expect(status.updateFunctionCalled).To(BeTrue())
...@@ -298,7 +298,7 @@ var _ = Describe("reconcile", func() { ...@@ -298,7 +298,7 @@ var _ = Describe("reconcile", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState() sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO() ctx := context.TODO()
req := getGreenProjectRequest() req := getGreenProjectRequest()
sut.gitlabClient.(*MockGitlabClient).getProjectVariableFunction = func(projectID int, key string) (*gitlab.ProjectVariable, int, error) { sut.gitlabClient.(*MockGitLabClient).getProjectVariableFunction = func(projectID int, key string) (*gitlab.ProjectVariable, int, error) {
return nil, 500, &MockError{message: "mocked getProjectVariable failure."} return nil, 500, &MockError{message: "mocked getProjectVariable failure."}
} }
result, err := sut.Reconcile(ctx, req) result, err := sut.Reconcile(ctx, req)
...@@ -311,17 +311,17 @@ var _ = Describe("reconcile", func() { ...@@ -311,17 +311,17 @@ var _ = Describe("reconcile", func() {
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorUpdatingProjectVariableInGitlab)) Expect(log.loggedMessage).To(Equal(errorUpdatingProjectVariableInGitLab))
}) })
It("should update the status of the project", func() { It("should update the status of the project", func() {
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitlab)) Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitLab))
}) })
}) })
Context("addProjectVariable fails", func() { Context("addProjectVariable fails", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState() sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO() ctx := context.TODO()
req := getGreenProjectRequest() req := getGreenProjectRequest()
sut.gitlabClient.(*MockGitlabClient).addProjectVariableFunction = func(groupID int, options gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) { sut.gitlabClient.(*MockGitLabClient).addProjectVariableFunction = func(groupID int, options gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) {
return nil, 500, &MockError{message: "mocked addProjectVariable failure."} return nil, 500, &MockError{message: "mocked addProjectVariable failure."}
} }
result, err := sut.Reconcile(ctx, req) result, err := sut.Reconcile(ctx, req)
...@@ -334,18 +334,18 @@ var _ = Describe("reconcile", func() { ...@@ -334,18 +334,18 @@ var _ = Describe("reconcile", func() {
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorUpdatingProjectVariableInGitlab)) Expect(log.loggedMessage).To(Equal(errorUpdatingProjectVariableInGitLab))
}) })
It("should update the status of the project", func() { It("should update the status of the project", func() {
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitlab)) Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitLab))
}) })
}) })
Context("updateProjectVariable fails", func() { Context("updateProjectVariable fails", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState() sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO() ctx := context.TODO()
req := getGreenProjectRequest() req := getGreenProjectRequest()
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0) sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0)
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{ sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{
Key: ManifestImageVariableName, Key: ManifestImageVariableName,
Value: "testValue", Value: "testValue",
VariableType: gitlab.EnvVariableType, VariableType: gitlab.EnvVariableType,
...@@ -353,7 +353,7 @@ var _ = Describe("reconcile", func() { ...@@ -353,7 +353,7 @@ var _ = Describe("reconcile", func() {
Masked: false, Masked: false,
EnvironmentScope: "*", EnvironmentScope: "*",
} }
sut.gitlabClient.(*MockGitlabClient).updateProjectVariableFunction = func(groupID int, key string, options gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) { sut.gitlabClient.(*MockGitLabClient).updateProjectVariableFunction = func(groupID int, key string, options gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, int, error) {
return nil, 500, &MockError{message: "updateProjectVariable Failure"} return nil, 500, &MockError{message: "updateProjectVariable Failure"}
} }
result, err := sut.Reconcile(ctx, req) result, err := sut.Reconcile(ctx, req)
...@@ -366,18 +366,18 @@ var _ = Describe("reconcile", func() { ...@@ -366,18 +366,18 @@ var _ = Describe("reconcile", func() {
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error")) Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorUpdatingProjectVariableInGitlab)) Expect(log.loggedMessage).To(Equal(errorUpdatingProjectVariableInGitLab))
}) })
It("should update the status of the project", func() { It("should update the status of the project", func() {
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitlab)) Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitLab))
}) })
}) })
Context("updateProjectVariable green state", func() { Context("updateProjectVariable green state", func() {
sut, _, _, _ := getProjectControllerWithMocksInGreenTestState() sut, _, _, _ := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO() ctx := context.TODO()
req := getGreenProjectRequest() req := getGreenProjectRequest()
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0) sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0)
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{ sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{
Key: ManifestImageVariableName, Key: ManifestImageVariableName,
Value: "testValue", Value: "testValue",
VariableType: gitlab.EnvVariableType, VariableType: gitlab.EnvVariableType,
...@@ -473,11 +473,11 @@ var _ = Describe("getProject", func() { ...@@ -473,11 +473,11 @@ var _ = Describe("getProject", func() {
}) })
}) })
var _ = Describe("getGitlabGroup", func() { var _ = Describe("getGitLabGroup", func() {
Context("green state", func() { Context("green state", func() {
sut, _, _, _ := getProjectControllerWithMocksInGreenTestState() sut, _, _, _ := getProjectControllerWithMocksInGreenTestState()
project := getGreenProject() project := getGreenProject()
group, err := sut.getGitlabGroup(context.TODO(), &project, getGreenProjectRequest()) group, err := sut.getGitLabGroup(context.TODO(), &project, getGreenProjectRequest())
It("should return a group, and no error.", func() { It("should return a group, and no error.", func() {
Expect(group).To(BeAssignableToTypeOf(&gitlab.Group{})) Expect(group).To(BeAssignableToTypeOf(&gitlab.Group{}))
Expect(err).To(BeNil()) Expect(err).To(BeNil())
...@@ -486,17 +486,17 @@ var _ = Describe("getGitlabGroup", func() { ...@@ -486,17 +486,17 @@ var _ = Describe("getGitlabGroup", func() {
Context("gitlab client returns error", func() { Context("gitlab client returns error", func() {
project := getGreenProject() project := getGreenProject()
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState() sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient.(*MockGitlabClient).getGroupFunction = func(groupID int) (*gitlab.Group, int, error) { sut.gitlabClient.(*MockGitLabClient).getGroupFunction = func(groupID int) (*gitlab.Group, int, error) {
return nil, 500, &MockError{ return nil, 500, &MockError{
message: "failure in getGitlabGroup", message: "failure in getGitLabGroup",
} }
} }
group, err := sut.getGitlabGroup(context.TODO(), &project, getGreenProjectRequest()) group, err := sut.getGitLabGroup(context.TODO(), &project, getGreenProjectRequest())
It("should return an error", func() { It("should return an error", func() {
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
}) })
It("should log the error", func() { It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorGettingGroupFromGitlab)) Expect(log.loggedMessage).To(Equal(errorGettingGroupFromGitLab))
}) })
It("should return no group", func() { It("should return no group", func() {
Expect(group).To(BeNil()) Expect(group).To(BeNil())
......
...@@ -24,7 +24,7 @@ func logGroupStart(logPrefix string, groupSpec apigitlab.GroupSpec) { ...@@ -24,7 +24,7 @@ func logGroupStart(logPrefix string, groupSpec apigitlab.GroupSpec) {
} }
// CreateGroup - // CreateGroup -
func CreateGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupSpec, httpClient *http.Client) error { func CreateGroup(gitlabCredentials GitLabCredentials, groupSpec apigitlab.GroupSpec, httpClient *http.Client) error {
logPrefix := "CreateGroup" logPrefix := "CreateGroup"
logGroupStart(logPrefix, groupSpec) logGroupStart(logPrefix, groupSpec)
...@@ -36,7 +36,7 @@ func CreateGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupS ...@@ -36,7 +36,7 @@ func CreateGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupS
// Identify parent Group for group // Identify parent Group for group
groupFullPath := groupSpec.FullPath groupFullPath := groupSpec.FullPath
groupParentFullPath, groupPath := ParseGitlabPath(groupFullPath) groupParentFullPath, groupPath := ParseGitLabPath(groupFullPath)
// strip any trailing / // strip any trailing /
groupParentFullPath = StripLastChar(groupParentFullPath, "/") groupParentFullPath = StripLastChar(groupParentFullPath, "/")
parentGroup, statusCode, err := client.GetGroupByFullPath(&groupParentFullPath) parentGroup, statusCode, err := client.GetGroupByFullPath(&groupParentFullPath)
...@@ -72,7 +72,7 @@ func CreateGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupS ...@@ -72,7 +72,7 @@ func CreateGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupS
} }
// DeleteGroup - // DeleteGroup -
func DeleteGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupSpec, httpClient *http.Client) error { func DeleteGroup(gitlabCredentials GitLabCredentials, groupSpec apigitlab.GroupSpec, httpClient *http.Client) error {
logPrefix := "DeleteGroup" logPrefix := "DeleteGroup"
logGroupStart(logPrefix, groupSpec) logGroupStart(logPrefix, groupSpec)
...@@ -103,7 +103,7 @@ func DeleteGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupS ...@@ -103,7 +103,7 @@ func DeleteGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupS
} }
// UpdateGroup - // UpdateGroup -
func UpdateGroup(gitlabCredentials GitlabCredentials, groupSpec apigitlab.GroupSpec, httpClient *http.Client) error { func UpdateGroup(gitlabCredentials GitLabCredentials, groupSpec apigitlab.GroupSpec, httpClient *http.Client) error {
logPrefix := "UpdateGroup" logPrefix := "UpdateGroup"
logGroupStart(logPrefix, groupSpec) logGroupStart(logPrefix, groupSpec)
......
...@@ -38,7 +38,7 @@ func TestCreateGroup(t *testing.T) { ...@@ -38,7 +38,7 @@ func TestCreateGroup(t *testing.T) {
testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"} testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"}
type args struct { type args struct {
gitlabCredentials GitlabCredentials gitlabCredentials GitLabCredentials
groupSpec apigitlab.GroupSpec groupSpec apigitlab.GroupSpec
httpClient *http.Client httpClient *http.Client
} }
...@@ -47,7 +47,7 @@ func TestCreateGroup(t *testing.T) { ...@@ -47,7 +47,7 @@ func TestCreateGroup(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{name: "test", args: args{gitlabCredentials: GitlabCredentials{testAPIUrl, testToken}, groupSpec: testGroupSpec, httpClient: testHTTPClient}, wantErr: false}, {name: "test", args: args{gitlabCredentials: GitLabCredentials{testAPIUrl, testToken}, groupSpec: testGroupSpec, httpClient: testHTTPClient}, wantErr: false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
...@@ -98,7 +98,7 @@ func TestDeleteGroup(t *testing.T) { ...@@ -98,7 +98,7 @@ func TestDeleteGroup(t *testing.T) {
testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"} testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"}
type args struct { type args struct {
gitlabCredentials GitlabCredentials gitlabCredentials GitLabCredentials
groupSpec apigitlab.GroupSpec groupSpec apigitlab.GroupSpec
httpClient *http.Client httpClient *http.Client
} }
...@@ -107,7 +107,7 @@ func TestDeleteGroup(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestDeleteGroup(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{name: "test", args: args{gitlabCredentials: GitlabCredentials{testAPIUrl, testToken}, groupSpec: testGroupSpec, httpClient: testHTTPClient}, wantErr: false}, {name: "test", args: args{gitlabCredentials: GitLabCredentials{testAPIUrl, testToken}, groupSpec: testGroupSpec, httpClient: testHTTPClient}, wantErr: false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
...@@ -150,7 +150,7 @@ func TestUpdateGroup(t *testing.T) { ...@@ -150,7 +150,7 @@ func TestUpdateGroup(t *testing.T) {
testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"} testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"}
type args struct { type args struct {
gitlabCredentials GitlabCredentials gitlabCredentials GitLabCredentials
groupSpec apigitlab.GroupSpec groupSpec apigitlab.GroupSpec
httpClient *http.Client httpClient *http.Client
} }
...@@ -159,7 +159,7 @@ func TestUpdateGroup(t *testing.T) { ...@@ -159,7 +159,7 @@ func TestUpdateGroup(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{name: "test", args: args{gitlabCredentials: GitlabCredentials{testAPIUrl, testToken}, groupSpec: testGroupSpec, httpClient: testHTTPClient}, wantErr: false}, {name: "test", args: args{gitlabCredentials: GitLabCredentials{testAPIUrl, testToken}, groupSpec: testGroupSpec, httpClient: testHTTPClient}, wantErr: false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
......
...@@ -36,11 +36,11 @@ func logProjectStart(logPrefix string, projectSpec apigitlab.ProjectSpec) { ...@@ -36,11 +36,11 @@ func logProjectStart(logPrefix string, projectSpec apigitlab.ProjectSpec) {
} }
// CreateProject - // CreateProject -
func CreateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.ProjectSpec, httpClient *http.Client) error { func CreateProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.ProjectSpec, httpClient *http.Client) error {
logPrefix := "CreateProject" logPrefix := "CreateProject"
logProjectStart(logPrefix, projectSpec) logProjectStart(logPrefix, projectSpec)
err := ValidateGitlabPath(projectSpec.FullPath) err := ValidateGitLabPath(projectSpec.FullPath)
if err != nil { if err != nil {
processProjectError(logPrefix, err) processProjectError(logPrefix, err)
return err return err
...@@ -54,7 +54,7 @@ func CreateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr ...@@ -54,7 +54,7 @@ func CreateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr
// Identify parent Group for project // Identify parent Group for project
projectFullPath := projectSpec.FullPath projectFullPath := projectSpec.FullPath
groupFullPath, projectPath := ParseGitlabPath(projectFullPath) groupFullPath, projectPath := ParseGitLabPath(projectFullPath)
// strip any trailing / // strip any trailing /
groupFullPath = StripLastChar(groupFullPath, "/") groupFullPath = StripLastChar(groupFullPath, "/")
parentGroup, statusCode, err := client.GetGroupByFullPath(&groupFullPath) parentGroup, statusCode, err := client.GetGroupByFullPath(&groupFullPath)
...@@ -119,11 +119,11 @@ func CreateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr ...@@ -119,11 +119,11 @@ func CreateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr
} }
// UpdateProject - // UpdateProject -
func UpdateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.ProjectSpec, httpClient *http.Client) error { func UpdateProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.ProjectSpec, httpClient *http.Client) error {
logPrefix := "UpdateProject" logPrefix := "UpdateProject"
logProjectStart(logPrefix, projectSpec) logProjectStart(logPrefix, projectSpec)
err := ValidateGitlabPath(projectSpec.FullPath) err := ValidateGitLabPath(projectSpec.FullPath)
if err != nil { if err != nil {
processProjectError(logPrefix, err) processProjectError(logPrefix, err)
return err return err
...@@ -137,7 +137,7 @@ func UpdateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr ...@@ -137,7 +137,7 @@ func UpdateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr
// Identify parent Group for project // Identify parent Group for project
projectFullPath := projectSpec.FullPath projectFullPath := projectSpec.FullPath
groupFullPath, projectPath := ParseGitlabPath(projectSpec.FullPath) groupFullPath, projectPath := ParseGitLabPath(projectSpec.FullPath)
// strip any trailing / // strip any trailing /
groupFullPath = StripLastChar(groupFullPath, "/") groupFullPath = StripLastChar(groupFullPath, "/")
group, _, err := client.GetGroupByFullPath(&groupFullPath) group, _, err := client.GetGroupByFullPath(&groupFullPath)
...@@ -179,7 +179,7 @@ func UpdateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr ...@@ -179,7 +179,7 @@ func UpdateProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr
} }
// DeleteProject - // DeleteProject -
func DeleteProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.ProjectSpec, httpClient *http.Client) error { func DeleteProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.ProjectSpec, httpClient *http.Client) error {
logPrefix := "DeleteProject" logPrefix := "DeleteProject"
logProjectStart(logPrefix, projectSpec) logProjectStart(logPrefix, projectSpec)
...@@ -212,9 +212,9 @@ func DeleteProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr ...@@ -212,9 +212,9 @@ func DeleteProject(gitlabCredentials GitlabCredentials, projectSpec apigitlab.Pr
// generateCIConfigPath - helper function. create CI configuration path for P1 // generateCIConfigPath - helper function. create CI configuration path for P1
func generateCIConfigPath(projectName string, parentGroupFullPath string) (string, error) { func generateCIConfigPath(projectName string, parentGroupFullPath string) (string, error) {
// scrub the project name // scrub the project name
projectPathString, err := GenerateGitlabPath(projectName) projectPathString, err := GenerateGitLabPath(projectName)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to GenerateGitlabPath with name %s error: %v", projectName, err) return "", fmt.Errorf("failed to GenerateGitLabPath with name %s error: %v", projectName, err)
} }
ciConfigPath := fmt.Sprintf("%s/%s-ci.yml@platform-one/devops/pipeline-products", parentGroupFullPath, projectPathString) ciConfigPath := fmt.Sprintf("%s/%s-ci.yml@platform-one/devops/pipeline-products", parentGroupFullPath, projectPathString)
return ciConfigPath, nil return ciConfigPath, nil
......
...@@ -52,7 +52,7 @@ func TestCreateProject(t *testing.T) { ...@@ -52,7 +52,7 @@ func TestCreateProject(t *testing.T) {
testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp} testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp}
type args struct { type args struct {
gitlabCredentials GitlabCredentials gitlabCredentials GitLabCredentials
projectSpec apigitlab.ProjectSpec projectSpec apigitlab.ProjectSpec
httpClient *http.Client httpClient *http.Client
} }
...@@ -61,7 +61,7 @@ func TestCreateProject(t *testing.T) { ...@@ -61,7 +61,7 @@ func TestCreateProject(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{name: "test", args: args{gitlabCredentials: GitlabCredentials{testAPIUrl, testToken}, projectSpec: testProjectSpec, httpClient: testHTTPClient}, wantErr: false}, {name: "test", args: args{gitlabCredentials: GitLabCredentials{testAPIUrl, testToken}, projectSpec: testProjectSpec, httpClient: testHTTPClient}, wantErr: false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
...@@ -113,7 +113,7 @@ func TestDeleteProject(t *testing.T) { ...@@ -113,7 +113,7 @@ func TestDeleteProject(t *testing.T) {
testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp} testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp}
type args struct { type args struct {
gitlabCredentials GitlabCredentials gitlabCredentials GitLabCredentials
projectSpec apigitlab.ProjectSpec projectSpec apigitlab.ProjectSpec
httpClient *http.Client httpClient *http.Client
} }
...@@ -122,7 +122,7 @@ func TestDeleteProject(t *testing.T) { ...@@ -122,7 +122,7 @@ func TestDeleteProject(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{name: "test", args: args{gitlabCredentials: GitlabCredentials{testAPIUrl, testToken}, projectSpec: testProjectSpec, httpClient: testHTTPClient}, wantErr: false}, {name: "test", args: args{gitlabCredentials: GitLabCredentials{testAPIUrl, testToken}, projectSpec: testProjectSpec, httpClient: testHTTPClient}, wantErr: false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
...@@ -176,7 +176,7 @@ func TestUpdateProject(t *testing.T) { ...@@ -176,7 +176,7 @@ func TestUpdateProject(t *testing.T) {
testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp} testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp}
type args struct { type args struct {
gitlabCredentials GitlabCredentials gitlabCredentials GitLabCredentials
projectSpec apigitlab.ProjectSpec projectSpec apigitlab.ProjectSpec
httpClient *http.Client httpClient *http.Client
} }
...@@ -185,7 +185,7 @@ func TestUpdateProject(t *testing.T) { ...@@ -185,7 +185,7 @@ func TestUpdateProject(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{name: "test", args: args{gitlabCredentials: GitlabCredentials{testAPIUrl, testToken}, projectSpec: testProjectSpec, httpClient: testHTTPClient}, wantErr: false}, {name: "test", args: args{gitlabCredentials: GitLabCredentials{testAPIUrl, testToken}, projectSpec: testProjectSpec, httpClient: testHTTPClient}, wantErr: false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
......
...@@ -4,8 +4,8 @@ import ( ...@@ -4,8 +4,8 @@ import (
"fmt" "fmt"
) )
// GitlabCredentials - // GitLabCredentials -
type GitlabCredentials struct { type GitLabCredentials struct {
ServerURL string ServerURL string
ServerToken string ServerToken string
} }
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"strings" "strings"
) )
// GenerateGitlabPath - use gitlab name to generate a path // GenerateGitLabPath - use gitlab name to generate a path
func GenerateGitlabPath(name string) (string, error) { func GenerateGitLabPath(name string) (string, error) {
var re *regexp.Regexp var re *regexp.Regexp
var path = name var path = name
...@@ -29,8 +29,8 @@ func GenerateGitlabPath(name string) (string, error) { ...@@ -29,8 +29,8 @@ func GenerateGitlabPath(name string) (string, error) {
return pathLower, nil return pathLower, nil
} }
// ParseGitlabPath - extract the basename from a path // ParseGitLabPath - extract the basename from a path
func ParseGitlabPath(fullpath string) (parent string, name string) { func ParseGitLabPath(fullpath string) (parent string, name string) {
parent, name = path.Split(fullpath) parent, name = path.Split(fullpath)
return parent, name return parent, name
} }
...@@ -45,8 +45,8 @@ func StripLastChar(value string, char string) string { ...@@ -45,8 +45,8 @@ func StripLastChar(value string, char string) string {
return newValue return newValue
} }
// ValidateGitlabPath - Insure gitlab path value is compliant with P1 // ValidateGitLabPath - Insure gitlab path value is compliant with P1
func ValidateGitlabPath(value string) error { func ValidateGitLabPath(value string) error {
if value == "" { if value == "" {
return fmt.Errorf("noncompliant gitlab path. path cannot an empty string") return fmt.Errorf("noncompliant gitlab path. path cannot an empty string")
} }
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"testing" "testing"
) )
func TestGenerateGitlabPath(t *testing.T) { func TestGenerateGitLabPath(t *testing.T) {
type args struct { type args struct {
name string name string
} }
...@@ -23,21 +23,21 @@ func TestGenerateGitlabPath(t *testing.T) { ...@@ -23,21 +23,21 @@ func TestGenerateGitlabPath(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := GenerateGitlabPath(tt.args.name) got, err := GenerateGitLabPath(tt.args.name)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("GenerateGitlabPath() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("GenerateGitLabPath() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
if got != tt.want { if got != tt.want {
t.Errorf("GenerateGitlabPath() FAIL '%v', want '%v'", got, tt.want) t.Errorf("GenerateGitLabPath() FAIL '%v', want '%v'", got, tt.want)
} else { } else {
t.Logf("GenerateGitlabPath() PASS input '%s' '%s', want '%s'", tt.args.name, got, tt.want) t.Logf("GenerateGitLabPath() PASS input '%s' '%s', want '%s'", tt.args.name, got, tt.want)
} }
}) })
} }
} }
func TestParseGitlabPath(t *testing.T) { func TestParseGitLabPath(t *testing.T) {
type args struct { type args struct {
fullpath string fullpath string
} }
...@@ -55,21 +55,21 @@ func TestParseGitlabPath(t *testing.T) { ...@@ -55,21 +55,21 @@ func TestParseGitlabPath(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
gotParent, gotName := ParseGitlabPath(tt.args.fullpath) gotParent, gotName := ParseGitLabPath(tt.args.fullpath)
if gotParent != tt.wantParent { if gotParent != tt.wantParent {
t.Errorf("ParseGitlabPath() gotParent = %v, want %v", gotParent, tt.wantParent) t.Errorf("ParseGitLabPath() gotParent = %v, want %v", gotParent, tt.wantParent)
return return
} }
if gotName != tt.wantName { if gotName != tt.wantName {
t.Errorf("ParseGitlabPath() gotName = %v, want %v", gotName, tt.wantName) t.Errorf("ParseGitLabPath() gotName = %v, want %v", gotName, tt.wantName)
return return
} }
t.Logf("TestParseGitlabPath() PASS input '%s', want '%s' '%s'", tt.args.fullpath, gotParent, gotName) t.Logf("TestParseGitLabPath() PASS input '%s', want '%s' '%s'", tt.args.fullpath, gotParent, gotName)
}) })
} }
} }
func TestValidateGitlabPath(t *testing.T) { func TestValidateGitLabPath(t *testing.T) {
type args struct { type args struct {
value string value string
} }
...@@ -86,8 +86,8 @@ func TestValidateGitlabPath(t *testing.T) { ...@@ -86,8 +86,8 @@ func TestValidateGitlabPath(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := ValidateGitlabPath(tt.args.value); (err != nil) != tt.wantErr { if err := ValidateGitLabPath(tt.args.value); (err != nil) != tt.wantErr {
t.Errorf("ValidateGitlabPath() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("ValidateGitLabPath() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })
} }
......
## Gitlab Projects ## GitLab Projects
### Reference ### Reference
- https://docs.gitlab.com/ee/api/projects.html - https://docs.gitlab.com/ee/api/projects.html
......
...@@ -33,5 +33,5 @@ This release will provide end users with a user interface to select tech stack a ...@@ -33,5 +33,5 @@ This release will provide end users with a user interface to select tech stack a
Valkyrie integrates with the following systems: Valkyrie integrates with the following systems:
- Launchboard provides the user interface for Valkyrie. It is developed by party bus team Bullhorn and has been granted a CtF by Platform One. - Launchboard provides the user interface for Valkyrie. It is developed by party bus team Bullhorn and has been granted a CtF by Platform One.
- Valkyrie extends the kubernetes API and leverages the cluster deployed into the Party Bus DSOP environments. - Valkyrie extends the kubernetes API and leverages the cluster deployed into the Party Bus DSOP environments.
- Valkyrie has write permission to Gitlab, SonarQube, Fortify, SD Elements to create projects, update settings, and publish "initial commit" project provisioning. - Valkyrie has write permission to GitLab, SonarQube, Fortify, SD Elements to create projects, update settings, and publish "initial commit" project provisioning.
...@@ -163,7 +163,7 @@ func (d driverImpl) instantiateControllers(mgr manager.Manager) []controllers.Ma ...@@ -163,7 +163,7 @@ func (d driverImpl) instantiateControllers(mgr manager.Manager) []controllers.Ma
}, },
&gitlabcontrollers.CredentialsReconciler{ &gitlabcontrollers.CredentialsReconciler{
Client: mgr.GetClient(), Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("gitlab").WithName("GitlabCredentials"), Log: ctrl.Log.WithName("controllers").WithName("gitlab").WithName("GitLabCredentials"),
Scheme: mgr.GetScheme(), Scheme: mgr.GetScheme(),
}, },
&gitlabcontrollers.DNSRepoCredentialReconciler{ &gitlabcontrollers.DNSRepoCredentialReconciler{
......
...@@ -43,7 +43,7 @@ var _ = Describe("instantiateControllers", func() { ...@@ -43,7 +43,7 @@ var _ = Describe("instantiateControllers", func() {
It("Should create an SD Elements Configuration Controller", func() { It("Should create an SD Elements Configuration Controller", func() {
Expect(controllers[7]).To(BeAssignableToTypeOf(&gitlab.SdElementsPipelineConfigurationReconciler{})) Expect(controllers[7]).To(BeAssignableToTypeOf(&gitlab.SdElementsPipelineConfigurationReconciler{}))
}) })
It("Should create a GitlabCredentials Controller", func() { It("Should create a GitLabCredentials Controller", func() {
Expect(controllers[8]).To(BeAssignableToTypeOf(&gitlab.CredentialsReconciler{})) Expect(controllers[8]).To(BeAssignableToTypeOf(&gitlab.CredentialsReconciler{}))
}) })
It("Should create a DNSRepoCredential Controller", func() { It("Should create a DNSRepoCredential Controller", func() {
......
...@@ -24,7 +24,7 @@ func Test_P1_AddGroup(t *testing.T) { ...@@ -24,7 +24,7 @@ func Test_P1_AddGroup(t *testing.T) {
FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath, FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath,
} }
creds := custom_p1.GitlabCredentials{ creds := custom_p1.GitLabCredentials{
ServerURL: P1Config.gitlabAPIURL, ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken, ServerToken: P1Config.gitlabAPIToken,
} }
...@@ -47,7 +47,7 @@ func Test_P1_UpdateGroup(t *testing.T) { ...@@ -47,7 +47,7 @@ func Test_P1_UpdateGroup(t *testing.T) {
FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath, FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath,
} }
creds := custom_p1.GitlabCredentials{ creds := custom_p1.GitLabCredentials{
ServerURL: P1Config.gitlabAPIURL, ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken, ServerToken: P1Config.gitlabAPIToken,
} }
...@@ -68,7 +68,7 @@ func Test_P1_DeleteGroup(t *testing.T) { ...@@ -68,7 +68,7 @@ func Test_P1_DeleteGroup(t *testing.T) {
FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath, FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath,
} }
creds := custom_p1.GitlabCredentials{ creds := custom_p1.GitLabCredentials{
ServerURL: P1Config.gitlabAPIURL, ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken, ServerToken: P1Config.gitlabAPIToken,
} }
......
...@@ -25,7 +25,7 @@ func Test_P1_AddProject(t *testing.T) { ...@@ -25,7 +25,7 @@ func Test_P1_AddProject(t *testing.T) {
Language: custom_p1.LangTypeAngular, Language: custom_p1.LangTypeAngular,
} }
creds := custom_p1.GitlabCredentials{ creds := custom_p1.GitLabCredentials{
ServerURL: P1Config.gitlabAPIURL, ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken, ServerToken: P1Config.gitlabAPIToken,
} }
...@@ -57,7 +57,7 @@ func Test_P1_UpdateProject(t *testing.T) { ...@@ -57,7 +57,7 @@ func Test_P1_UpdateProject(t *testing.T) {
Language: custom_p1.LangTypeJavaMaven, Language: custom_p1.LangTypeJavaMaven,
} }
creds := custom_p1.GitlabCredentials{ creds := custom_p1.GitLabCredentials{
ServerURL: P1Config.gitlabAPIURL, ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken, ServerToken: P1Config.gitlabAPIToken,
} }
...@@ -78,7 +78,7 @@ func Test_P1_UpdateProject(t *testing.T) { ...@@ -78,7 +78,7 @@ func Test_P1_UpdateProject(t *testing.T) {
// FullPath: p1IntegrationRootGroupPath + "/" + integrationTestProjectPath, // FullPath: p1IntegrationRootGroupPath + "/" + integrationTestProjectPath,
// } // }
// creds := custom_p1.GitlabCredentials{ // creds := custom_p1.GitLabCredentials{
// ServerURL: P1Config.gitlabAPIURL, // ServerURL: P1Config.gitlabAPIURL,
// ServerToken: P1Config.gitlabAPIToken, // ServerToken: P1Config.gitlabAPIToken,
// } // }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment