UNCLASSIFIED

Commit 91938a2c authored by Jason van Brackel's avatar Jason van Brackel Committed by abrichards
Browse files

Partial work for the Pipeline configuration controller.

parent 576ebc79
......@@ -48,7 +48,7 @@ const (
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"
errorUpdatingGroupVariableInGitLab = "Error updating group variable in Gitlab"
)
// Group Status
......@@ -59,9 +59,9 @@ const (
// Group CI/CD Variables to Manage
const (
KustomizeStagingPathVariableName = "KUSTOMIZE_STAGING_PATH"
KustomizeProductionPathVariableName = "KUSTOMIZE_PRODUCTION_PATH"
ManifestRepoURLVariableName = "MANIFEST_REPO_URL"
KustomizeStagingPathVariableName = "KUSTOMIZE_STAGING_PATH"
KustomizeProductionPathVariableName = "KUSTOMIZE_PRODUCTION_PATH"
ManifestRepoURLVariableName = "MANIFEST_REPO_URL"
)
const valkyrie = "valkyrie"
......@@ -345,6 +345,7 @@ func (r *GroupReconciler) updateCiVariables(ID int, group *gitlabv1alpha1.Group)
}
// CreateCiVariable -
func (r *GroupReconciler) CreateCiVariable(ID int, variableToCreate string, group *gitlabv1alpha1.Group) (*gitlab.GroupVariable, int, error) {
envType := gitlab.EnvVariableType
protected := true
......@@ -364,9 +365,9 @@ func (r *GroupReconciler) CreateCiVariable(ID int, variableToCreate string, grou
}
return r.gitlabClient.AddGroupVariable(ID, options)
}
// GetGroupVariableValueByName -
func (r *GroupReconciler) GetGroupVariableValueByName(variableToCreate string, group *gitlabv1alpha1.Group) string {
switch variableToCreate {
case KustomizeStagingPathVariableName:
......
......@@ -288,7 +288,7 @@ var _ = Describe("Reconcile", func() {
Context("createCiVariable fails", func() {
sut, log, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
gitlabClient.addGroupVariableFunction = func(groupID int, options gitlab.CreateGroupVariableOptions) (*gitlab.GroupVariable, int, error) {
return nil, 500, &MockError{ "addGroupVariable mocked error"}
return nil, 500, &MockError{"addGroupVariable mocked error"}
}
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() {
......@@ -305,7 +305,7 @@ var _ = Describe("Reconcile", func() {
Context("updateGroupVariable fails", func() {
sut, log, _, _, gitlabClient := getGroupControllerWithMocksInGreenTestState()
gitlabClient.updateGroupVariableFunction = func(groupID int, key string, options gitlab.UpdateGroupVariableOptions) (*gitlab.GroupVariable, int, error) {
return nil, 500, &MockError{ "updateGroupVariable mocked error"}
return nil, 500, &MockError{"updateGroupVariable mocked error"}
}
result, err := sut.Reconcile(context.TODO(), getGreenGroupControllerRequest())
It("should log the error", func() {
......@@ -589,17 +589,17 @@ func TestGroupReconciler_GetGroupVariableValueByName(t *testing.T) {
group *gitlabv1alpha1.Group
}
group := getGreenGroup()
tests := []struct {
name string
args args
want string
name string
args args
want string
}{
{
name: "should return value of " + KustomizeProductionPathVariableName,
args: args{
variableToCreate: KustomizeProductionPathVariableName,
group: group,
group: group,
},
want: group.Spec.KustomizeProductionPath,
},
......@@ -607,7 +607,7 @@ func TestGroupReconciler_GetGroupVariableValueByName(t *testing.T) {
name: "should return value of " + KustomizeStagingPathVariableName,
args: args{
variableToCreate: KustomizeStagingPathVariableName,
group: group,
group: group,
},
want: group.Spec.KustomizeStagingPath,
},
......@@ -615,7 +615,7 @@ func TestGroupReconciler_GetGroupVariableValueByName(t *testing.T) {
name: "should return value of " + ManifestRepoURLVariableName,
args: args{
variableToCreate: ManifestRepoURLVariableName,
group: group,
group: group,
},
want: group.Spec.ManifestRepositoryURL,
},
......@@ -623,7 +623,7 @@ func TestGroupReconciler_GetGroupVariableValueByName(t *testing.T) {
name: "should return no value",
args: args{
variableToCreate: "not supported",
group: group,
group: group,
},
want: "",
},
......@@ -654,4 +654,4 @@ var _ = Describe("CreateCiVariable", func() {
Expect(err).To(BeNil())
})
})
})
\ No newline at end of file
})
......@@ -44,24 +44,25 @@ type ProjectReconciler struct {
// errors
const (
errorWhileLookingUpProject = "error while looking up project."
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."
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"
errorWhileLookingUpProject = "error while looking up project."
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."
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"
)
)
// statuses
const (
groupDoesntExist string = "GitlabGroupDoesNotExist"
)
// ManifestImageVariableName -
const ManifestImageVariableName = "MANIFEST_IMAGE"
const annotationKeyID = "ID"
......@@ -240,7 +241,7 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri
masked := false
environmentScope := "*"
if projectVariable, statusCode, err = r.gitlabClient.GetProjectVariable(id, ManifestImageVariableName); err != nil{
if projectVariable, statusCode, err = r.gitlabClient.GetProjectVariable(id, ManifestImageVariableName); err != nil {
if statusCode == 404 {
if projectVariable, statusCode, err = r.gitlabClient.AddProjectVariable(id, gitlab.CreateProjectVariableOptions{
Key: &key,
......@@ -267,12 +268,11 @@ func (r *ProjectReconciler) updateManifestImageSetting(id int, manifestPath stri
EnvironmentScope: &projectVariable.EnvironmentScope,
})
if err != nil{
if err != nil {
r.Log.Error(err, errorWhileUpdatingProjectVariableInGitlab, "statusCode", statusCode)
return projectVariable, err
}
return projectVariable, err
}
......@@ -35,7 +35,7 @@ func getGreenProject() v1alpha1.Project {
VirtualService: GreenNamespace,
ServicePort: 8081,
Language: "golang",
ManifestImage: "manifestImage",
ManifestImage: "manifestImage",
},
Status: v1alpha1.ProjectStatus{
URL: "https://example.com/TestProject",
......@@ -344,7 +344,7 @@ var _ = Describe("reconcile", func() {
sut, _, log, status := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO()
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{
Key: ManifestImageVariableName,
Value: "testValue",
......@@ -376,7 +376,7 @@ var _ = Describe("reconcile", func() {
sut, _, _, _ := getProjectControllerWithMocksInGreenTestState()
ctx := context.TODO()
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{
Key: ManifestImageVariableName,
Value: "testValue",
......@@ -486,7 +486,7 @@ 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",
}
......
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