UNCLASSIFIED

......@@ -41,7 +41,7 @@ var _ = Describe("gitlabcredentials_controller", func() {
})
})
Describe("SetupWithManager", func() {
gitlabv1alpha1.SchemeBuilder.Register(&gitlabv1alpha1.GitLabCredentials{}, &gitlabv1alpha1.GitLabCredentialsList{})
gitlabv1alpha1.SchemeBuilder.Register(&gitlabv1alpha1.GitlabCredentials{}, &gitlabv1alpha1.GitlabCredentialsList{})
sut := CredentialsReconciler{
Client: nil,
Log: nil,
......@@ -58,7 +58,7 @@ var _ = Describe("gitlabcredentials_controller", func() {
startWasCalled: false,
}
It("Should setup the GitLab Controller to be managed by the manager", func() {
It("Should setup the Gitlab Controller to be managed by the manager", func() {
Expect(sut.SetupWithManager(&mgr)).To(BeNil())
})
})
......
......@@ -28,7 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"strconv"
"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"
gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab"
)
......@@ -37,18 +37,19 @@ import (
const (
errorUnableToFetchGroup = "unable to fetch group"
errorWhileSearchingGroups = "Error while searching groups"
errorWhileCreatingGitLabGroup = "Error while creating GitLab group"
errorWhileUpdatingGitLabGroup = "Error while updating GitLab group"
errorWhileCreatingGitlabGroup = "Error while creating Gitlab group"
errorWhileUpdatingGitlabGroup = "Error while updating Gitlab group"
errorUnableToUpdateStatus = "Unable to update status"
errorUnableToProcessProjects = "Unable to process projects"
errorTryingToCreateProject = "Error trying to create project"
errorLookingUpProject = "Error looking up project"
errorUpdatingProject = "Error updating project"
errorUnableToSetupGitLabClient = "Error unable to setup GitLab client"
errorWhileUpdatingGitLabGroupCiVariables = "Error updating the GitLab group CI variables"
errorGettingGroupVariablesFromGitLab = "Error getting group variables from GitLab"
errorCreatingGroupVariableInGitLab = "Error creating group variable in GitLab"
errorUpdatingGroupVariableInGitLab = "Error updating group variable in GitLab"
errorUnableToSetupGitlabClient = "Error unable to setup Gitlab client"
errorWhileUpdatingGitlabGroupCiVariables = "Error updating the Gitlab group CI variables"
errorGettingGroupVariablesFromGitlab = "Error getting group variables from Gitlab"
errorCreatingGroupVariableInGitlab = "Error creating group variable in Gitlab"
errorUpdatingGroupVariableInGitlab = "Error updating group variable in Gitlab"
errorWhileUpdatingGroupState = "Error while updating group state in status"
)
// Group Status
......@@ -66,14 +67,14 @@ const (
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.
type GroupReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
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
......@@ -86,7 +87,7 @@ type GroupReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// 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) {
r.Log = r.Log.WithValues("group", req.NamespacedName)
......@@ -105,14 +106,15 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
// Do a nil check here so we can use mock gitlabClients
if r.gitlabClient == nil {
if r.gitlabClientConfiguration == nil {
r.gitlabClientConfiguration = apisGitLab.ClientConfigurationImpl{
r.gitlabClientConfiguration = apisGitlab.ClientConfigurationImpl{
Log: r.Log,
Ctx: ctx,
Req: req,
}
}
if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, group.Spec.GitLabCredentialsName); err != nil {
r.Log.Error(err, errorUnableToSetupGitLabClient)
if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, group.Spec.GitlabCredentialsName); err != nil {
r.Log.Error(err, errorUnableToSetupGitlabClient)
_ = r.updateState(ctx, group, errorUnableToSetupGitlabClient)
return ctrl.Result{Requeue: true}, err
}
}
......@@ -121,34 +123,40 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
var gitlabGroup *gitlab.Group
found, gitlabGroup, err := r.groupExists(group)
if err != nil {
r.Log.Error(err, errorWhileSearchingGroups, "status")
r.Log.Error(err, errorWhileSearchingGroups)
_ = r.updateState(ctx, group, errorWhileSearchingGroups)
return ctrl.Result{Requeue: true}, err
}
if !found {
if gitlabGroup, _, err = r.createGroup(group); err != nil {
r.Log.Error(err, errorWhileCreatingGitLabGroup, "group", group)
r.Log.Error(err, errorWhileCreatingGitlabGroup, "group", group)
_ = r.updateState(ctx, group, errorWhileCreatingGitlabGroup)
return ctrl.Result{Requeue: true}, err
}
} else {
if gitlabGroup, _, err = r.updateGroup(group); err != nil {
r.Log.Error(err, errorWhileUpdatingGitLabGroup, "group", group)
r.Log.Error(err, errorWhileUpdatingGitlabGroup, "group", group)
_ = r.updateState(ctx, group, errorWhileUpdatingGitlabGroup)
return ctrl.Result{Requeue: true}, err
}
}
if err = r.updateCiVariables(gitlabGroup.ID, group); err != nil {
r.Log.Error(err, errorWhileUpdatingGitLabGroupCiVariables, "group", group)
r.Log.Error(err, errorWhileUpdatingGitlabGroupCiVariables, "group", group)
_ = r.updateState(ctx, group, errorWhileUpdatingGitlabGroupCiVariables)
return ctrl.Result{Requeue: true}, err
}
if err = r.updateStatus(ctx, gitlabGroup.ID, group); err != nil {
r.Log.Error(err, errorUnableToUpdateStatus, "group", group)
_ = r.updateState(ctx, group, errorUnableToUpdateStatus)
return ctrl.Result{Requeue: true}, err
}
if err = r.processProjects(ctx, group, group.Spec.ProjectSpecs); err != nil {
r.Log.Error(err, errorUnableToProcessProjects, "group", group)
_ = r.updateState(ctx, group, errorUnableToProcessProjects)
return ctrl.Result{Requeue: true}, err
}
......@@ -296,7 +304,11 @@ func (r *GroupReconciler) updateStatus(ctx context.Context, id int, group *gitla
}
}
return r.Status().Update(ctx, group)
if err := r.Status().Update(ctx, group); err != nil {
r.Log.Error(err, errorUnableToUpdateStatus)
return err
}
return nil
}
// SetupWithManager sets up the controller with the Manager.
......@@ -308,7 +320,7 @@ func (r *GroupReconciler) SetupWithManager(mgr ctrl.Manager) error {
}
func (r *GroupReconciler) updateCiVariables(ID int, group *gitlabv1alpha1.Group) error {
var variablesToUpdate []string = []string{KustomizeStagingPathVariableName, KustomizeProductionPathVariableName, ManifestRepoURLVariableName}
var variablesToUpdate = []string{KustomizeStagingPathVariableName, KustomizeProductionPathVariableName, ManifestRepoURLVariableName}
var err error
var groupVariable *gitlab.GroupVariable
......@@ -317,11 +329,11 @@ func (r *GroupReconciler) updateCiVariables(ID int, group *gitlabv1alpha1.Group)
for _, variableToUpdate := range variablesToUpdate {
if groupVariable, statusCode, err = r.gitlabClient.GetGroupVariable(ID, variableToUpdate); err != nil {
if statusCode != 404 {
r.Log.Error(err, errorGettingGroupVariablesFromGitLab, "statusCode", statusCode, "variable", variablesToUpdate)
r.Log.Error(err, errorGettingGroupVariablesFromGitlab, "statusCode", statusCode, "variable", variablesToUpdate)
return err
}
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
}
} else {
......@@ -335,7 +347,7 @@ func (r *GroupReconciler) updateCiVariables(ID int, group *gitlabv1alpha1.Group)
}
if groupVariable, statusCode, err = r.gitlabClient.UpdateGroupVariable(ID, groupVariable.Key, option); err != nil {
r.Log.Error(err, errorUpdatingGroupVariableInGitLab, "statusCode", statusCode, "variable", variablesToUpdate)
r.Log.Error(err, errorUpdatingGroupVariableInGitlab, "statusCode", statusCode, "variable", variablesToUpdate)
return err
}
}
......@@ -379,3 +391,12 @@ func (r *GroupReconciler) GetGroupVariableValueByName(variableToCreate string, g
}
return ""
}
func (r *GroupReconciler) updateState(ctx context.Context, group *gitlabv1alpha1.Group, state string) error {
group.Status.State = state
if err := r.Client.Status().Update(ctx, group); err != nil {
r.Log.Error(err, errorWhileUpdatingGroupState, "group", group)
return err
}
return nil
}
......@@ -42,7 +42,7 @@ func getGreenGroup() *gitlabv1alpha1.Group {
FullPath: "/greenGroup",
Name: "greenGroup",
Description: "a green Group",
GitLabCredentialsName: "greenCredentialsName",
GitlabCredentialsName: "greenCredentialsName",
KustomizeProductionPath: "/kustomize/prod/path",
KustomizeStagingPath: "/kustomize/staging/path",
ManifestRepositoryURL: "https://gitserver/manifest/repo/url",
......@@ -62,7 +62,7 @@ func getGreenGroup() *gitlabv1alpha1.Group {
GroupID: greenGroupID,
Name: "A Green Project",
FullPath: "/greenGroup/greenProject",
GitLabCredentialsName: "greenCredentialsName",
GitlabCredentialsName: "greenCredentialsName",
ImpactLevel: "2",
StorageTypes: nil,
VirtualService: "",
......@@ -74,7 +74,7 @@ func getGreenGroup() *gitlabv1alpha1.Group {
return returnGroup
}
func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogger, *MockClientConfiguration, *MockClient, *MockGitLabClient) {
func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogger, *MockClientConfiguration, *MockClient, *MockGitlabClient) {
builder := gitlabv1alpha1.SchemeBuilder.Register(&gitlabv1alpha1.Group{}, &gitlabv1alpha1.GroupList{})
scheme, _ := builder.Build()
loggerMock := MockLogger{
......@@ -91,10 +91,10 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge
Name: greenGroupName,
}] = greenGroup
expectedGitLabGroups := make(map[int]*gitlab.Group)
expectedGitLabGroups[greenGroupID] = getGreenGitLabGroup()
gitlabClientMock := MockGitLabClient{
expectedGroups: expectedGitLabGroups,
expectedGitlabGroups := make(map[int]*gitlab.Group)
expectedGitlabGroups[greenGroupID] = getGreenGitlabGroup()
gitlabClientMock := MockGitlabClient{
expectedGroups: expectedGitlabGroups,
}
key := ManifestRepoURLVariableName
......@@ -114,7 +114,7 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge
gitlabClientMock.AddGroupVariable(greenGroupID, options)
configurationMock := MockClientConfiguration{
GitLabClient: &gitlabClientMock,
GitlabClient: &gitlabClientMock,
SetupClientFunction: nil,
SetupClientCalled: false,
}
......@@ -127,7 +127,7 @@ func getGroupControllerWithMocksInGreenTestState() (*GroupReconciler, *MockLogge
return &sut, &loggerMock, &configurationMock, &clientMock, &gitlabClientMock
}
func getGreenGitLabGroup() *gitlab.Group {
func getGreenGitlabGroup() *gitlab.Group {
return &gitlab.Group{
ID: greenGroupID,
Path: "/aGreenGroup",
......@@ -184,7 +184,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() {
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() {
Expect(result).To(Equal(ctrl.Result{
......@@ -192,11 +192,14 @@ var _ = Describe("Reconcile", func() {
}))
Expect(err).ToNot(BeNil())
})
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorUnableToSetupGitlabClient))
})
})
Context("groupExists fails", func() {
sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState()
sut.gitlabClient = &MockGitLabClient{
sut.gitlabClient = &MockGitlabClient{
newClientFunction: func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) {
return &gitlab.Client{}, nil
},
......@@ -217,11 +220,14 @@ var _ = Describe("Reconcile", func() {
It("should return an error", func() {
Expect(err).NotTo(BeNil())
})
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorWhileSearchingGroups))
})
})
Context("createGroup fails", func() {
sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState()
sut.gitlabClient = &MockGitLabClient{
sut.gitlabClient = &MockGitlabClient{
newClientFunction: func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error) {
return &gitlab.Client{}, nil
},
......@@ -241,11 +247,14 @@ var _ = Describe("Reconcile", func() {
})
It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorWhileCreatingGitLabGroup))
Expect(logger.loggedMessage).To(Equal(errorWhileCreatingGitlabGroup))
})
It("should return an error", func() {
Expect(err).NotTo(BeNil())
})
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorWhileCreatingGitlabGroup))
})
})
Context("updateGroup fails", func() {
sut, logger, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
......@@ -262,11 +271,14 @@ var _ = Describe("Reconcile", func() {
})
It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroup))
Expect(logger.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroup))
})
It("should return an error", func() {
Expect(err).NotTo(BeNil())
})
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorWhileUpdatingGitlabGroup))
})
})
Context("getGroupVariable fails", func() {
sut, log, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
......@@ -276,7 +288,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroupCiVariables))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroupCiVariables))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
......@@ -284,6 +296,9 @@ var _ = Describe("Reconcile", func() {
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorWhileUpdatingGitlabGroupCiVariables))
})
})
Context("createCiVariable fails", func() {
sut, log, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
......@@ -293,7 +308,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroupCiVariables))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroupCiVariables))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
......@@ -301,6 +316,9 @@ var _ = Describe("Reconcile", func() {
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorWhileUpdatingGitlabGroupCiVariables))
})
})
Context("updateGroupVariable fails", func() {
sut, log, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
......@@ -310,7 +328,7 @@ var _ = Describe("Reconcile", func() {
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitLabGroupCiVariables))
Expect(log.loggedMessage).To(Equal(errorWhileUpdatingGitlabGroupCiVariables))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
......@@ -318,25 +336,8 @@ var _ = Describe("Reconcile", func() {
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
})
Context("updateStatus fails", func() {
sut, logger, _, kubernetesClient, _ := getGroupControllerWithMocksInGreenTestState()
kubernetesClient.statusWriter = &MockStatusWriter{
updateFunction: func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
return &MockError{"updateStatus fails"}
},
}
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
})
It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorUnableToUpdateStatus))
})
It("should return an error", func() {
Expect(err).NotTo(BeNil())
It("should update the state of the object", func() {
Expect(sut.Status().(*MockStatusWriter).updatedObject.(*gitlabv1alpha1.Group).Status.State).To(Equal(errorWhileUpdatingGitlabGroupCiVariables))
})
})
Context("processProjects fails", func() {
......@@ -362,6 +363,42 @@ var _ = Describe("Reconcile", func() {
})
})
var _ = Describe("updateState fails", func() {
sut, logger, _, _, _ := getGroupControllerWithMocksInGreenTestState()
sut.Status().(*MockStatusWriter).updateFunction = func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
return &MockError{message: "mock updateState error"}
}
result := sut.updateState(context.TODO(), getGreenGroup(), "")
It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorWhileUpdatingGroupState))
})
It("should return an error", func() {
Expect(result).ToNot(BeNil())
})
})
var _ = Describe("updateStatus fails", func() {
sut, logger, _, kubernetesClient, _ := getGroupControllerWithMocksInGreenTestState()
kubernetesClient.statusWriter = &MockStatusWriter{
updateFunction: func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
return &MockError{"updateStatus fails"}
},
}
ctx := context.TODO()
group := getGreenGroup()
err := sut.updateStatus(ctx, 1, group)
It("should log the error", func() {
Expect(logger.logLevelCalled).To(Equal("Error"))
Expect(logger.loggedMessage).To(Equal(errorUnableToUpdateStatus))
})
It("should return an error", func() {
Expect(err).NotTo(BeNil())
})
})
var _ = Describe("groupExists", func() {
When("the gitlab client fails", func() {
sut, _, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
......
......@@ -414,7 +414,7 @@ func (m *MockError) Error() string {
return m.message
}
type MockGitLabClient struct {
type MockGitlabClient struct {
newClientFunction func(token string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error)
getGroupsFunction func(name *string) ([]*gitlab.Group, int, error)
getGroupVariableFunction func(groupID int, key string) (*gitlab.GroupVariable, int, error)
......@@ -439,7 +439,7 @@ type MockGitLabClient struct {
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 {
return m.getGroupVariableFunction(groupID, key)
}
......@@ -457,7 +457,7 @@ func (m *MockGitLabClient) GetGroupVariable(groupID int, key string) (*gitlab.Gr
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 {
m.expectedGroupVariables = make(map[string]*gitlab.GroupVariable)
}
......@@ -471,7 +471,7 @@ func (m *MockGitLabClient) GetGroupVariables(groupID int) ([]*gitlab.GroupVariab
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 {
m.expectedProjectVariables = make(map[string]*gitlab.ProjectVariable)
}
......@@ -485,7 +485,7 @@ func (m *MockGitLabClient) GetProjectVariables(projectID int) ([]*gitlab.Project
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 {
return m.getProjectVariableFunction(projectID, key)
}
......@@ -502,7 +502,7 @@ func (m *MockGitLabClient) GetProjectVariable(projectID int, key string) (*gitla
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 {
return m.addGroupVariableFunction(groupID, options)
}
......@@ -525,7 +525,7 @@ func (m *MockGitLabClient) AddGroupVariable(groupID int, options gitlab.CreateGr
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 {
return m.updateGroupVariableFunction(groupID, key, options)
}
......@@ -547,7 +547,7 @@ func (m *MockGitLabClient) UpdateGroupVariable(groupID int, key string, options
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 {
m.expectedGroupVariables = make(map[string]*gitlab.GroupVariable)
}
......@@ -561,7 +561,7 @@ func (m *MockGitLabClient) DeleteGroupVariable(groupID int, key string, waitInte
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 {
return m.addProjectVariableFunction(projectID, options)
}
......@@ -583,7 +583,7 @@ func (m *MockGitLabClient) AddProjectVariable(projectID int, options gitlab.Crea
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 {
return m.updateProjectVariableFunction(projectID, key, options)
}
......@@ -605,7 +605,7 @@ func (m *MockGitLabClient) UpdateProjectVariable(projectID int, key string, opti
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 {
m.expectedProjectVariables = make(map[string]*gitlab.ProjectVariable)
}
......@@ -619,39 +619,39 @@ func (m *MockGitLabClient) DeleteProjectVariable(projectID int, key string, wait
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")
}
func (m *MockGitLabClient) GetUsers(search *string) ([]*gitlab.User, error) {
func (m *MockGitlabClient) GetUsers(search *string) ([]*gitlab.User, error) {
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")
}
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")
}
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")
}
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")
}
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")
}
func (m *MockGitLabClient) GetGroupByFullPath(fullPath *string) (*gitlab.Group, int, error) {
func (m *MockGitlabClient) GetGroupByFullPath(fullPath *string) (*gitlab.Group, int, error) {
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.expectedGroups == nil {
return make([]*gitlab.Group, 0), nil
......@@ -677,15 +677,15 @@ func (m *MockGitLabClient) GetGroups(search *string) ([]*gitlab.Group, error) {
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")
}
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")
}
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 statusCode int
var err error
......@@ -708,15 +708,15 @@ func (m *MockGitLabClient) GetProject(projectID int) (*gitlab.Project, int, erro
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")
}
func (m *MockGitLabClient) GetProjects(search *string) ([]*gitlab.Project, error) {
func (m *MockGitlabClient) GetProjects(search *string) ([]*gitlab.Project, error) {
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 {
return m.addProjectFunction(createProjectOptions)
}
......@@ -733,7 +733,7 @@ func (m *MockGitLabClient) AddProject(createProjectOptions gitlab.CreateProjectO
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 {
return m.updateProjectFunction(projectID, editProjectOptions)
}
......@@ -750,43 +750,43 @@ func (m *MockGitLabClient) UpdateProject(projectID int, editProjectOptions gitla
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")
}
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 {
return m.getMRByIDFunc(projectID, mergeRequestID)
}
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 {
return m.getMRsFunc(projectID, sourceBranch, targetBranch)
}
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 {
return m.createMRFunc(projectID, mrOptions)
}
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")
}
func (m *MockGitLabClient) CloseMergeRequest(projectID int, mergeRequestID int) error {
func (m *MockGitlabClient) CloseMergeRequest(projectID int, mergeRequestID int) error {
if m.closeMRFunc != nil {
return m.closeMRFunc(projectID, mergeRequestID)
}
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 {
return m.getGroupFunction(groupID)
}
......@@ -798,7 +798,7 @@ func (m *MockGitLabClient) GetGroup(groupID int) (*gitlab.Group, int, error) {
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.expectedGroups == nil {
m.expectedGroups = make(map[int]*gitlab.Group)
......@@ -813,7 +813,7 @@ func (m *MockGitLabClient) AddGroup(options gitlab.CreateGroupOptions) (*gitlab.
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.expectedGroups == nil {
m.expectedGroups = make(map[int]*gitlab.Group)
......@@ -878,7 +878,7 @@ func (m *MockRepoClient) DeleteRemoteBranch(branchName string) (err error) {
}
type MockClientConfiguration struct {
GitLabClient gitlabClient.Client
GitlabClient gitlabClient.Client
SetupClientFunction func(client client.Client, credentialsName string) (gitlabClient.Client, error)
SetupClientCalled bool
}
......@@ -887,10 +887,10 @@ func (m *MockClientConfiguration) SetupClient(client client.Client, credentialsN
m.SetupClientCalled = true
if m.SetupClientFunction == nil {
if m.GitLabClient == nil {
return &MockGitLabClient{}, nil
if m.GitlabClient == nil {
return &MockGitlabClient{}, nil
}
return m.GitLabClient, nil
return m.GitlabClient, nil
}
return m.SetupClientFunction(client, credentialsName)
......
......@@ -24,7 +24,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"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"
gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab"
)
......@@ -35,7 +35,7 @@ type ProjectReconciler struct {
Log logr.Logger
Scheme *runtime.Scheme
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
......@@ -45,21 +45,21 @@ type ProjectReconciler struct {
// errors
const (
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."
errorGettingProjectFromGitLab = "Error getting project from GitLab."
errorCreatingGitLabProject = "Error creating GitLab project."
errorUpdatingGitLabProject = "Error updating GitLab project."
errorGettingProjectFromGitlab = "Error getting project from Gitlab."
errorCreatingGitlabProject = "Error creating Gitlab project."
errorUpdatingGitlabProject = "Error updating Gitlab project."
errorUpdatingProjectIDAnnotation = "Error updating project ID annotation."
errorUpdatingProjectVariableInGitLab = "Error updating project variable in GitLab"
errorGettingProjectVariableFromGitLab = "Error getting project variable from GitLab"
errorCreatingProjectVariableInGitLab = "Error creating project variable in GitLab"
errorWhileUpdatingProjectVariableInGitLab = "Error while updating project variable in gitlab"
errorUpdatingProjectVariableInGitlab = "Error updating project variable in Gitlab"
errorGettingProjectVariableFromGitlab = "Error getting project variable from Gitlab"
errorCreatingProjectVariableInGitlab = "Error creating project variable in Gitlab"
errorWhileUpdatingProjectVariableInGitlab = "Error while updating project variable in gitlab"
)
// statuses
const (
groupDoesntExist string = "GitLabGroupDoesNotExist"
groupDoesntExist string = "GitlabGroupDoesNotExist"
)
// ManifestImageVariableName -
......@@ -67,7 +67,7 @@ const ManifestImageVariableName = "MANIFEST_IMAGE"
const annotationKeyID = "ID"
// Reconcile is the main reconciliation loop that will create/edit/delete GitLab Projects.
// 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) {
r.Log = r.Log.WithValues("project", req.NamespacedName)
......@@ -84,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
if r.gitlabClient == nil {
if r.gitlabClientConfiguration == nil {
r.gitlabClientConfiguration = apisGitLab.ClientConfigurationImpl{
r.gitlabClientConfiguration = apisGitlab.ClientConfigurationImpl{
Log: r.Log,
Ctx: ctx,
Req: req,
}
}
if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, project.Spec.GitLabCredentialsName); err != nil {
r.Log.Error(err, errorUnableToSetupGitLabClient)
_ = r.updateStatus(ctx, project, errorUnableToSetupGitLabClient)
if r.gitlabClient, err = r.gitlabClientConfiguration.SetupClient(r.Client, project.Spec.GitlabCredentialsName); err != nil {
r.Log.Error(err, errorUnableToSetupGitlabClient)
_ = r.updateStatus(ctx, project, errorUnableToSetupGitlabClient)
return ctrl.Result{Requeue: true}, err
}
}
// Make Sure the Group Exists in GitLab
if _, err = r.getGitLabGroup(ctx, project, req); err != nil {
r.Log.Error(err, errorGettingGroupFromGitLab, "request", req)
// Make Sure the Group Exists in Gitlab
if _, err = r.getGitlabGroup(ctx, project, req); err != nil {
r.Log.Error(err, errorGettingGroupFromGitlab, "request", req)
_ = r.updateStatus(ctx, project, groupDoesntExist)
return ctrl.Result{Requeue: true}, err
}
......@@ -108,28 +108,28 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
var gitlabProject *gitlab.Project
id, _ := strconv.Atoi(project.ObjectMeta.Annotations["ID"])
if gitlabProject, err = r.getGitLabProject(id); err != nil {
r.Log.Error(err, errorGettingProjectFromGitLab)
_ = r.updateStatus(ctx, project, errorGettingProjectFromGitLab)
if gitlabProject, err = r.getGitlabProject(id); err != nil {
r.Log.Error(err, errorGettingProjectFromGitlab)
_ = r.updateStatus(ctx, project, errorGettingProjectFromGitlab)
return ctrl.Result{Requeue: true}, err
}
if gitlabProject == nil {
if gitlabProject, err = r.createGitLabProject(project); err != nil {
r.Log.Error(err, errorCreatingGitLabProject)
_ = r.updateStatus(ctx, project, errorCreatingGitLabProject)
if gitlabProject, err = r.createGitlabProject(project); err != nil {
r.Log.Error(err, errorCreatingGitlabProject)
_ = r.updateStatus(ctx, project, errorCreatingGitlabProject)
return ctrl.Result{Requeue: true}, err
}
}
if gitlabProject, err = r.updateGitLabProject(id, project); err != nil {
r.Log.Error(err, errorUpdatingGitLabProject)
_ = r.updateStatus(ctx, project, errorUpdatingGitLabProject)
if gitlabProject, err = r.updateGitlabProject(id, project, gitlabProject); err != nil {
r.Log.Error(err, errorUpdatingGitlabProject)
_ = r.updateStatus(ctx, project, errorUpdatingGitlabProject)
return ctrl.Result{Requeue: true}, err
}
if _, err = r.updateManifestImageSetting(id, project.Spec.ManifestImage); err != nil {
r.Log.Error(err, errorUpdatingProjectVariableInGitLab)
_ = r.updateStatus(ctx, project, errorUpdatingProjectVariableInGitLab)
r.Log.Error(err, errorUpdatingProjectVariableInGitlab)
_ = r.updateStatus(ctx, project, errorUpdatingProjectVariableInGitlab)
return ctrl.Result{Requeue: true}, err
}
......@@ -169,20 +169,20 @@ func (r *ProjectReconciler) getProject(ctx context.Context, request ctrl.Request
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 response int
var err error
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 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 statusCode int
var err error
......@@ -196,13 +196,20 @@ func (r *ProjectReconciler) getGitLabProject(id int) (*gitlab.Project, error) {
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 err error
autoCancelPendingPipelines := "enabled"
ciForwardDeploymentEnabled := true
publicBuilds := true
createProjectOptions := gitlab.CreateProjectOptions{
Name: &project.Spec.Name,
Path: &project.Spec.FullPath,
CIConfigPath: &project.Spec.CiConfigurationPath,
Name: &project.Spec.Name,
Path: &project.Spec.FullPath,
CIConfigPath: &project.Spec.CiConfigurationPath,
AutoCancelPendingPipelines: &autoCancelPendingPipelines,
CIForwardDeploymentEnabled: &ciForwardDeploymentEnabled,
PublicBuilds: &publicBuilds,
}
if gitLabProject, _, err = r.gitlabClient.AddProject(createProjectOptions); err != nil {
return nil, err
......@@ -211,13 +218,15 @@ func (r *ProjectReconciler) createGitLabProject(project *v1alpha1.Project) (*git
return gitLabProject, nil
}
func (r *ProjectReconciler) updateGitLabProject(id int, project *v1alpha1.Project) (*gitlab.Project, error) {
var gitLabProject *gitlab.Project
func (r *ProjectReconciler) updateGitlabProject(id int, project *v1alpha1.Project, gitLabProject *gitlab.Project) (*gitlab.Project, error) {
var err error
if gitLabProject, _, err = r.gitlabClient.UpdateProject(id, gitlab.EditProjectOptions{
Name: &project.Spec.Name,
Path: &project.Spec.FullPath,
CIConfigPath: &project.Spec.CiConfigurationPath,
Name: &project.Spec.Name,
Path: &project.Spec.FullPath,
CIConfigPath: &project.Spec.CiConfigurationPath,
CIForwardDeploymentEnabled: &gitLabProject.CIForwardDeploymentEnabled,
PublicBuilds: &gitLabProject.PublicBuilds,
}); err != nil {
return nil, err
}
......@@ -252,12 +261,12 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri
Masked: &masked,
EnvironmentScope: &environmentScope,
}); err != nil {
r.Log.Error(err, errorCreatingProjectVariableInGitLab, "statusCode", statusCode)
r.Log.Error(err, errorCreatingProjectVariableInGitlab, "statusCode", statusCode)
return projectVariable, err
}
return projectVariable, err
}
r.Log.Error(err, errorGettingProjectVariableFromGitLab, "statusCode", statusCode)
r.Log.Error(err, errorGettingProjectVariableFromGitlab, "statusCode", statusCode)
return projectVariable, err
}
......@@ -270,7 +279,7 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri
})
if err != nil {
r.Log.Error(err, errorWhileUpdatingProjectVariableInGitLab, "statusCode", statusCode)
r.Log.Error(err, errorWhileUpdatingProjectVariableInGitlab, "statusCode", statusCode)
return projectVariable, err
}
......
......@@ -9,7 +9,7 @@ import (
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"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"
gitlabClient "valkyrie.dso.mil/valkyrie-api/clients/gitlab"
)
......@@ -28,14 +28,17 @@ func getGreenProject() v1alpha1.Project {
Annotations: make(map[string]string, 0),
},
Spec: v1alpha1.ProjectSpec{
Name: GreenProjectName,
FullPath: "https://example.com/TestProject",
ImpactLevel: "2",
StorageTypes: nil,
VirtualService: GreenNamespace,
ServicePort: 8081,
Language: "golang",
ManifestImage: "manifestImage",
GroupID: 1,
Name: GreenProjectName,
FullPath: "https://example.com/TestProject",
GitlabCredentialsName: "",
ImpactLevel: "2",
StorageTypes: nil,
VirtualService: GreenNamespace,
ServicePort: 8081,
Language: "golang",
ManifestImage: "manifestImage",
CiConfigurationPath: "",
},
Status: v1alpha1.ProjectStatus{
URL: "https://example.com/TestProject",
......@@ -80,7 +83,7 @@ func getProjectControllerWithMocksInGreenTestState() (ProjectReconciler, *MockMa
builder: builder,
}
gitlabClient := MockGitLabClient{}
gitlabClient := MockGitlabClient{}
sut := ProjectReconciler{
Client: &clientMock,
......@@ -129,7 +132,7 @@ var _ = Describe("reconcile", func() {
sut.gitlabClientConfiguration = nil
sut.Reconcile(context.TODO(), getGreenProjectRequest())
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() {
......@@ -144,7 +147,7 @@ var _ = Describe("reconcile", func() {
result, err := sut.Reconcile(context.TODO(), request)
It("should log the error", func() {
Expect(log.logLevelCalled).To(Equal("Error"))
Expect(log.loggedMessage).To(Equal(errorUnableToSetupGitLabClient))
Expect(log.loggedMessage).To(Equal(errorUnableToSetupGitlabClient))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
......@@ -195,31 +198,31 @@ var _ = Describe("reconcile", func() {
Expect(log.loggedMessage).To(Equal(errorWhileLookingUpProject))
})
})
Context("getGitLabProject returns an error", func() {
failingGitLabClient := MockGitLabClient{
Context("getGitlabProject returns an error", func() {
failingGitlabClient := MockGitlabClient{
getProjectFunction: func(groupID int) (*gitlab.Project, int, error) {
return nil, 500, &MockError{
message: "failure in getGitLabProject",
message: "failure in getGitlabProject",
}
},
}
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitLabClient
sut.gitlabClient = &failingGitlabClient
request := getRequestWithDefaultNamespacedTestProject()
result, err := sut.Reconcile(context.TODO(), request)
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorGettingProjectFromGitLab))
Expect(log.loggedMessage).To(Equal(errorGettingProjectFromGitlab))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
})
})
Context("createGitLabProject returns an error", func() {
failingGitLabClient := MockGitLabClient{
Context("createGitlabProject returns an error", func() {
failingGitlabClient := MockGitlabClient{
addProjectFunction: func(options gitlab.CreateProjectOptions) (*gitlab.Project, int, error) {
return nil, 500, &MockError{
message: "failure in addProject",
......@@ -227,56 +230,56 @@ var _ = Describe("reconcile", func() {
},
}
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitLabClient
sut.gitlabClient = &failingGitlabClient
request := getRequestWithDefaultNamespacedTestProject()
result, err := sut.Reconcile(context.TODO(), request)
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorCreatingGitLabProject))
Expect(log.loggedMessage).To(Equal(errorCreatingGitlabProject))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
})
})
Context("updateGitLabProject returns an error", func() {
failingGitLabClient := MockGitLabClient{
Context("updateGitlabProject returns an error", func() {
failingGitlabClient := MockGitlabClient{
getProjectFunction: func(projectID int) (*gitlab.Project, int, error) {
return &gitlab.Project{}, 1, nil
},
updateProjectFunction: func(int, gitlab.EditProjectOptions) (*gitlab.Project, int, error) {
return nil, 500, &MockError{
message: "failure in updateGitLabProject",
message: "failure in updateGitlabProject",
}
},
}
sut, _, log, _ := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitLabClient
sut.gitlabClient = &failingGitlabClient
request := getRequestWithDefaultNamespacedTestProject()
result, err := sut.Reconcile(context.TODO(), request)
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorUpdatingGitLabProject))
Expect(log.loggedMessage).To(Equal(errorUpdatingGitlabProject))
})
It("should requeue the object", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
})
})
Context("getGitLabGroup returns an error", func() {
failingGitLabClient := MockGitLabClient{
Context("getGitlabGroup returns an error", func() {
failingGitlabClient := MockGitlabClient{
getGroupFunction: func(groupID int) (*gitlab.Group, int, error) {
return nil, 500, &MockError{
message: "failure in getGitLabGroup",
message: "failure in getGitlabGroup",
}
},
}
sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
sut.gitlabClient = &failingGitLabClient
sut.gitlabClient = &failingGitlabClient
request := getGreenProjectRequest()
......@@ -288,7 +291,7 @@ var _ = Describe("reconcile", func() {
Expect(result).To(Equal(ctrl.Result{Requeue: true}))
})
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() {
Expect(status.updateFunctionCalled).To(BeTrue())
......@@ -298,7 +301,7 @@ var _ = Describe("reconcile", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO()
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."}
}
result, err := sut.Reconcile(ctx, req)
......@@ -311,17 +314,17 @@ var _ = Describe("reconcile", func() {
})
It("should log the error", func() {
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() {
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitLab))
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitlab))
})
})
Context("addProjectVariable fails", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO()
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."}
}
result, err := sut.Reconcile(ctx, req)
......@@ -334,18 +337,18 @@ var _ = Describe("reconcile", func() {
})
It("should log the error", func() {
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() {
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitLab))
Expect(status.updatedObject.(*v1alpha1.Project).Status.State).To(Equal(errorUpdatingProjectVariableInGitlab))
})
})
Context("updateProjectVariable fails", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO()
req := getGreenProjectRequest()
sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0)
sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0)
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{
Key: ManifestImageVariableName,
Value: "testValue",
VariableType: gitlab.EnvVariableType,
......@@ -353,7 +356,7 @@ var _ = Describe("reconcile", func() {
Masked: false,
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"}
}
result, err := sut.Reconcile(ctx, req)
......@@ -366,18 +369,18 @@ var _ = Describe("reconcile", func() {
})
It("should log the error", func() {
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() {
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() {
sut, _, _, _ := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO()
req := getGreenProjectRequest()
sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0)
sut.gitlabClient.(*MockGitLabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables = make(map[string]*gitlab.ProjectVariable, 0)
sut.gitlabClient.(*MockGitlabClient).expectedProjectVariables[ManifestImageVariableName] = &gitlab.ProjectVariable{
Key: ManifestImageVariableName,
Value: "testValue",
VariableType: gitlab.EnvVariableType,
......@@ -473,11 +476,11 @@ var _ = Describe("getProject", func() {
})
})
var _ = Describe("getGitLabGroup", func() {
var _ = Describe("getGitlabGroup", func() {
Context("green state", func() {
sut, _, _, _ := getProjectControllerWithMocksInGreenTestState()
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() {
Expect(group).To(BeAssignableToTypeOf(&gitlab.Group{}))
Expect(err).To(BeNil())
......@@ -486,17 +489,17 @@ var _ = Describe("getGitLabGroup", func() {
Context("gitlab client returns error", func() {
project := getGreenProject()
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{
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() {
Expect(err).ToNot(BeNil())
})
It("should log the error", func() {
Expect(log.loggedMessage).To(Equal(errorGettingGroupFromGitLab))
Expect(log.loggedMessage).To(Equal(errorGettingGroupFromGitlab))
})
It("should return no group", func() {
Expect(group).To(BeNil())
......
......@@ -58,7 +58,7 @@ var _ = Describe("twistlockcredential_controller", func() {
startWasCalled: false,
}
It("Should setup the GitLab Controller to be managed by the manager", func() {
It("Should setup the Gitlab Controller to be managed by the manager", func() {
Expect(sut.SetupWithManager(&mgr)).To(BeNil())
})
})
......
......@@ -24,7 +24,7 @@ func logGroupStart(logPrefix string, groupSpec apigitlab.GroupSpec) {
}
// 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"
logGroupStart(logPrefix, groupSpec)
......@@ -36,7 +36,7 @@ func CreateGroup(gitlabCredentials GitLabCredentials, groupSpec apigitlab.GroupS
// Identify parent Group for group
groupFullPath := groupSpec.FullPath
groupParentFullPath, groupPath := ParseGitLabPath(groupFullPath)
groupParentFullPath, groupPath := ParseGitlabPath(groupFullPath)
// strip any trailing /
groupParentFullPath = StripLastChar(groupParentFullPath, "/")
parentGroup, statusCode, err := client.GetGroupByFullPath(&groupParentFullPath)
......@@ -72,7 +72,7 @@ func CreateGroup(gitlabCredentials GitLabCredentials, groupSpec apigitlab.GroupS
}
// 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"
logGroupStart(logPrefix, groupSpec)
......@@ -103,7 +103,7 @@ func DeleteGroup(gitlabCredentials GitLabCredentials, groupSpec apigitlab.GroupS
}
// 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"
logGroupStart(logPrefix, groupSpec)
......
......@@ -38,7 +38,7 @@ func TestCreateGroup(t *testing.T) {
testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"}
type args struct {
gitlabCredentials GitLabCredentials
gitlabCredentials GitlabCredentials
groupSpec apigitlab.GroupSpec
httpClient *http.Client
}
......@@ -47,7 +47,7 @@ func TestCreateGroup(t *testing.T) {
args args
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 {
t.Run(tt.name, func(t *testing.T) {
......@@ -98,7 +98,7 @@ func TestDeleteGroup(t *testing.T) {
testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"}
type args struct {
gitlabCredentials GitLabCredentials
gitlabCredentials GitlabCredentials
groupSpec apigitlab.GroupSpec
httpClient *http.Client
}
......@@ -107,7 +107,7 @@ func TestDeleteGroup(t *testing.T) {
args args
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 {
t.Run(tt.name, func(t *testing.T) {
......@@ -150,7 +150,7 @@ func TestUpdateGroup(t *testing.T) {
testGroupSpec := apigitlab.GroupSpec{FullPath: testGroupFullPath, Name: "Group Name", Description: "Group Description"}
type args struct {
gitlabCredentials GitLabCredentials
gitlabCredentials GitlabCredentials
groupSpec apigitlab.GroupSpec
httpClient *http.Client
}
......@@ -159,7 +159,7 @@ func TestUpdateGroup(t *testing.T) {
args args
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 {
t.Run(tt.name, func(t *testing.T) {
......
......@@ -36,11 +36,11 @@ func logProjectStart(logPrefix string, projectSpec apigitlab.ProjectSpec) {
}
// 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"
logProjectStart(logPrefix, projectSpec)
err := ValidateGitLabPath(projectSpec.FullPath)
err := ValidateGitlabPath(projectSpec.FullPath)
if err != nil {
processProjectError(logPrefix, err)
return err
......@@ -54,7 +54,7 @@ func CreateProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.Pr
// Identify parent Group for project
projectFullPath := projectSpec.FullPath
groupFullPath, projectPath := ParseGitLabPath(projectFullPath)
groupFullPath, projectPath := ParseGitlabPath(projectFullPath)
// strip any trailing /
groupFullPath = StripLastChar(groupFullPath, "/")
parentGroup, statusCode, err := client.GetGroupByFullPath(&groupFullPath)
......@@ -119,11 +119,11 @@ func CreateProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.Pr
}
// 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"
logProjectStart(logPrefix, projectSpec)
err := ValidateGitLabPath(projectSpec.FullPath)
err := ValidateGitlabPath(projectSpec.FullPath)
if err != nil {
processProjectError(logPrefix, err)
return err
......@@ -137,7 +137,7 @@ func UpdateProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.Pr
// Identify parent Group for project
projectFullPath := projectSpec.FullPath
groupFullPath, projectPath := ParseGitLabPath(projectSpec.FullPath)
groupFullPath, projectPath := ParseGitlabPath(projectSpec.FullPath)
// strip any trailing /
groupFullPath = StripLastChar(groupFullPath, "/")
group, _, err := client.GetGroupByFullPath(&groupFullPath)
......@@ -179,7 +179,7 @@ func UpdateProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.Pr
}
// 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"
logProjectStart(logPrefix, projectSpec)
......@@ -212,9 +212,9 @@ func DeleteProject(gitlabCredentials GitLabCredentials, projectSpec apigitlab.Pr
// generateCIConfigPath - helper function. create CI configuration path for P1
func generateCIConfigPath(projectName string, parentGroupFullPath string) (string, error) {
// scrub the project name
projectPathString, err := GenerateGitLabPath(projectName)
projectPathString, err := GenerateGitlabPath(projectName)
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)
return ciConfigPath, nil
......
......@@ -52,7 +52,7 @@ func TestCreateProject(t *testing.T) {
testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp}
type args struct {
gitlabCredentials GitLabCredentials
gitlabCredentials GitlabCredentials
projectSpec apigitlab.ProjectSpec
httpClient *http.Client
}
......@@ -61,7 +61,7 @@ func TestCreateProject(t *testing.T) {
args args
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 {
t.Run(tt.name, func(t *testing.T) {
......@@ -113,7 +113,7 @@ func TestDeleteProject(t *testing.T) {
testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp}
type args struct {
gitlabCredentials GitLabCredentials
gitlabCredentials GitlabCredentials
projectSpec apigitlab.ProjectSpec
httpClient *http.Client
}
......@@ -122,7 +122,7 @@ func TestDeleteProject(t *testing.T) {
args args
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 {
t.Run(tt.name, func(t *testing.T) {
......@@ -176,7 +176,7 @@ func TestUpdateProject(t *testing.T) {
testProjectSpec := apigitlab.ProjectSpec{FullPath: testProjectFullPath, Name: "Project Name", Language: LangTypeCpp}
type args struct {
gitlabCredentials GitLabCredentials
gitlabCredentials GitlabCredentials
projectSpec apigitlab.ProjectSpec
httpClient *http.Client
}
......@@ -185,7 +185,7 @@ func TestUpdateProject(t *testing.T) {
args args
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 {
t.Run(tt.name, func(t *testing.T) {
......
......@@ -4,8 +4,8 @@ import (
"fmt"
)
// GitLabCredentials -
type GitLabCredentials struct {
// GitlabCredentials -
type GitlabCredentials struct {
ServerURL string
ServerToken string
}
......
......@@ -7,8 +7,8 @@ import (
"strings"
)
// GenerateGitLabPath - use gitlab name to generate a path
func GenerateGitLabPath(name string) (string, error) {
// GenerateGitlabPath - use gitlab name to generate a path
func GenerateGitlabPath(name string) (string, error) {
var re *regexp.Regexp
var path = name
......@@ -29,8 +29,8 @@ func GenerateGitLabPath(name string) (string, error) {
return pathLower, nil
}
// ParseGitLabPath - extract the basename from a path
func ParseGitLabPath(fullpath string) (parent string, name string) {
// ParseGitlabPath - extract the basename from a path
func ParseGitlabPath(fullpath string) (parent string, name string) {
parent, name = path.Split(fullpath)
return parent, name
}
......@@ -45,8 +45,8 @@ func StripLastChar(value string, char string) string {
return newValue
}
// ValidateGitLabPath - Insure gitlab path value is compliant with P1
func ValidateGitLabPath(value string) error {
// ValidateGitlabPath - Insure gitlab path value is compliant with P1
func ValidateGitlabPath(value string) error {
if value == "" {
return fmt.Errorf("noncompliant gitlab path. path cannot an empty string")
}
......
......@@ -4,7 +4,7 @@ import (
"testing"
)
func TestGenerateGitLabPath(t *testing.T) {
func TestGenerateGitlabPath(t *testing.T) {
type args struct {
name string
}
......@@ -23,21 +23,21 @@ func TestGenerateGitLabPath(t *testing.T) {
}
for _, tt := range tests {
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 {
t.Errorf("GenerateGitLabPath() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("GenerateGitlabPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
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 {
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 {
fullpath string
}
......@@ -55,21 +55,21 @@ func TestParseGitLabPath(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotParent, gotName := ParseGitLabPath(tt.args.fullpath)
gotParent, gotName := ParseGitlabPath(tt.args.fullpath)
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
}
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
}
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 {
value string
}
......@@ -86,8 +86,8 @@ func TestValidateGitLabPath(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := ValidateGitLabPath(tt.args.value); (err != nil) != tt.wantErr {
t.Errorf("ValidateGitLabPath() error = %v, wantErr %v", err, tt.wantErr)
if err := ValidateGitlabPath(tt.args.value); (err != nil) != tt.wantErr {
t.Errorf("ValidateGitlabPath() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
......
## GitLab Projects
## Gitlab Projects
### Reference
- 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
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.
- 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
},
&gitlabcontrollers.CredentialsReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("gitlab").WithName("GitLabCredentials"),
Log: ctrl.Log.WithName("controllers").WithName("gitlab").WithName("GitlabCredentials"),
Scheme: mgr.GetScheme(),
},
&gitlabcontrollers.DNSRepoCredentialReconciler{
......
......@@ -43,7 +43,7 @@ var _ = Describe("instantiateControllers", func() {
It("Should create an SD Elements Configuration Controller", func() {
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{}))
})
It("Should create a DNSRepoCredential Controller", func() {
......
......@@ -24,7 +24,7 @@ func Test_P1_AddGroup(t *testing.T) {
FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath,
}
creds := custom_p1.GitLabCredentials{
creds := custom_p1.GitlabCredentials{
ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken,
}
......@@ -47,7 +47,7 @@ func Test_P1_UpdateGroup(t *testing.T) {
FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath,
}
creds := custom_p1.GitLabCredentials{
creds := custom_p1.GitlabCredentials{
ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken,
}
......@@ -68,7 +68,7 @@ func Test_P1_DeleteGroup(t *testing.T) {
FullPath: p1IntegrationRootGroupPath + "/" + integrationTestGroupPath,
}
creds := custom_p1.GitLabCredentials{
creds := custom_p1.GitlabCredentials{
ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken,
}
......
......@@ -25,7 +25,7 @@ func Test_P1_AddProject(t *testing.T) {
Language: custom_p1.LangTypeAngular,
}
creds := custom_p1.GitLabCredentials{
creds := custom_p1.GitlabCredentials{
ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken,
}
......@@ -57,7 +57,7 @@ func Test_P1_UpdateProject(t *testing.T) {
Language: custom_p1.LangTypeJavaMaven,
}
creds := custom_p1.GitLabCredentials{
creds := custom_p1.GitlabCredentials{
ServerURL: P1Config.gitlabAPIURL,
ServerToken: P1Config.gitlabAPIToken,
}
......@@ -78,7 +78,7 @@ func Test_P1_UpdateProject(t *testing.T) {
// FullPath: p1IntegrationRootGroupPath + "/" + integrationTestProjectPath,
// }
// creds := custom_p1.GitLabCredentials{
// creds := custom_p1.GitlabCredentials{
// ServerURL: P1Config.gitlabAPIURL,
// ServerToken: P1Config.gitlabAPIToken,
// }
......