From 09ef6eeb160f6935b928c497d2f1cb746d69928d Mon Sep 17 00:00:00 2001 From: Jason van Brackel Date: Fri, 16 Jul 2021 11:27:43 -0400 Subject: [PATCH] feat: Add CI Config file to project reconciler --- PROJECT | 2 +- apis/gitlab/clientConfiguration.go | 20 +-- .../v1alpha1/dnsrepocredential_types.go | 4 +- .../v1alpha1/dnsrepocredential_types_test.go | 4 +- .../v1alpha1/gitlabcredentials_types.go | 32 ++-- .../v1alpha1/gitlabcredentials_types_test.go | 108 ++++++------- apis/gitlab/v1alpha1/group_types.go | 8 +- apis/gitlab/v1alpha1/group_types_test.go | 4 +- apis/gitlab/v1alpha1/project_types.go | 8 +- apis/gitlab/v1alpha1/zz_generated.deepcopy.go | 38 ++--- clients/gitlab/client_test.go | 146 +++++++++--------- ...b.valkyrie.dso.mil_dnsrepocredentials.yaml | 4 +- ...ab.valkyrie.dso.mil_gitlabcredentials.yaml | 22 +-- .../bases/gitlab.valkyrie.dso.mil_groups.yaml | 13 +- .../gitlab.valkyrie.dso.mil_projects.yaml | 7 +- .../gitlab_v1alpha1_gitlabcredentials.yaml | 2 +- .../gitlab/dnsrepomergerequest_controller.go | 8 +- .../dnsrepomergerequest_controller_test.go | 18 +-- .../gitlab/gitlabcredentials_controller.go | 4 +- .../gitlabcredentials_controller_test.go | 2 +- controllers/gitlab/group_controller.go | 38 ++--- controllers/gitlab/group_controller_test.go | 34 ++-- controllers/gitlab/mocks_test.go | 80 +++++----- controllers/gitlab/project_controller.go | 98 ++++++------ controllers/gitlab/project_controller_test.go | 84 +++++----- custom/p1/group.go | 8 +- custom/p1/group_test.go | 12 +- custom/p1/project.go | 18 +-- custom/p1/project_test.go | 12 +- custom/p1/types.go | 4 +- custom/p1/utils.go | 12 +- custom/p1/utils_test.go | 26 ++-- docs/gitlab/projects/README.ms | 2 +- docs/path-to-ctf/plan_of_action.md | 2 +- driver.go | 2 +- driver_test.go | 2 +- integration-tests/custom/p1/p1_groups_test.go | 6 +- .../custom/p1/p1_projects_test.go | 6 +- 38 files changed, 451 insertions(+), 449 deletions(-) diff --git a/PROJECT b/PROJECT index b52f58d..0c7fc78 100644 --- a/PROJECT +++ b/PROJECT @@ -101,7 +101,7 @@ resources: controller: true domain: valkyrie.dso.mil group: gitlab - kind: GitlabCredentials + kind: GitLabCredentials path: valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1 version: v1alpha1 - api: diff --git a/apis/gitlab/clientConfiguration.go b/apis/gitlab/clientConfiguration.go index 71af563..8255c06 100755 --- a/apis/gitlab/clientConfiguration.go +++ b/apis/gitlab/clientConfiguration.go @@ -12,14 +12,14 @@ import ( ) const ( - errorUnableToFetchGitlabCredentials = "unable to fetch gitlab credentials" + errorUnableToFetchGitLabCredentials = "unable to fetch gitlab credentials" errorUnableToFetchSecret = "unable to fetch secret from gitlab credentials" - errorUnableToCreateGitlabClient = "unable to create gitlab client" + errorUnableToCreateGitLabClient = "unable to create gitlab client" ) -// ClientConfiguration represents an object whose purpose is to setup a Gitlab client given +// ClientConfiguration represents an object whose purpose is to setup a GitLab client given type ClientConfiguration interface { - // SetupClient pulls the GitlabCredentials from Kubernetes and supplies the Gitlab user and access token. + // SetupClient pulls the GitLabCredentials from Kubernetes and supplies the GitLab user and access token. SetupClient(client client.Client, credentialsName string) (gitlabClient.Client, error) } @@ -31,18 +31,18 @@ type ClientConfigurationImpl struct { Req ctrl.Request } -// SetupClient looks up the gitlab credentials to get the access token and username for connecting to Gitlab +// SetupClient looks up the gitlab credentials to get the access token and username for connecting to GitLab // on behalf of the reconciler. func (c ClientConfigurationImpl) SetupClient(client client.Client, credentialsName string) (gitlabClient.Client, error) { - // Get the Gitlab Credentials + // Get the GitLab Credentials var gitLabCredentialsName = types.NamespacedName{ Namespace: c.Req.Namespace, Name: credentialsName, } - var gitlabCredentials gitlabv1alpha1.GitlabCredentials + var gitlabCredentials gitlabv1alpha1.GitLabCredentials if err := client.Get(c.Ctx, gitLabCredentialsName, &gitlabCredentials); err != nil { - c.Log.Error(err, errorUnableToFetchGitlabCredentials) + c.Log.Error(err, errorUnableToFetchGitLabCredentials) return nil, err } @@ -58,13 +58,13 @@ func (c ClientConfigurationImpl) SetupClient(client client.Client, credentialsNa return nil, err } - // Login to Gitlab + // Login to GitLab var accessToken = string(secret.Data[gitlabCredentials.Spec.AccessTokenKey]) var returnClient gitlabClient.Client var err error if returnClient, err = gitlabClient.NewClient(accessToken, gitlabCredentials.Spec.URL, nil); err != nil { - c.Log.Error(err, errorUnableToCreateGitlabClient, "username", gitlabCredentials.Spec.Username, "url", gitlabCredentials.Spec.URL) + c.Log.Error(err, errorUnableToCreateGitLabClient, "username", gitlabCredentials.Spec.Username, "url", gitlabCredentials.Spec.URL) return nil, err } diff --git a/apis/gitlab/v1alpha1/dnsrepocredential_types.go b/apis/gitlab/v1alpha1/dnsrepocredential_types.go index 87cde53..be70355 100644 --- a/apis/gitlab/v1alpha1/dnsrepocredential_types.go +++ b/apis/gitlab/v1alpha1/dnsrepocredential_types.go @@ -26,8 +26,8 @@ type DNSRepoCredentialSpec struct { // RepoURL is the url for the DNS git repository. For example: https://code.il2.dso.mil/platform-one/products/valkyrie/dso-dns.git RepoURL string `json:"repoUrl,omitempty"` - // GitlabProjectID is the project ID of the DNS project in Gitlab - GitlabProjectID int `json:"gitlabProjectId,omitempty"` + // GitLabProjectID is the project ID of the DNS project in GitLab + GitLabProjectID int `json:"gitlabProjectId,omitempty"` // UsernameSecRef is the username of project bot will be used to clone the repo UsernameSecRef v1.SecretKeySelector `json:"usernameSecretRef,omitempty"` diff --git a/apis/gitlab/v1alpha1/dnsrepocredential_types_test.go b/apis/gitlab/v1alpha1/dnsrepocredential_types_test.go index 874f82a..a90b6a3 100644 --- a/apis/gitlab/v1alpha1/dnsrepocredential_types_test.go +++ b/apis/gitlab/v1alpha1/dnsrepocredential_types_test.go @@ -69,7 +69,7 @@ func initVarsDNSRepoCredential() testVarsDNSRepoCredential { // leave scaffold Foo value for testing? testVars.testObjectSpec1 = DNSRepoCredentialSpec{ RepoURL: "https://test.git", - GitlabProjectID: 4351, + GitLabProjectID: 4351, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secret"}, Key: "username", @@ -81,7 +81,7 @@ func initVarsDNSRepoCredential() testVarsDNSRepoCredential { } testVars.testObjectSpec2 = DNSRepoCredentialSpec{ RepoURL: "https://test22.git", - GitlabProjectID: 4351, + GitLabProjectID: 4351, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secret"}, Key: "username", diff --git a/apis/gitlab/v1alpha1/gitlabcredentials_types.go b/apis/gitlab/v1alpha1/gitlabcredentials_types.go index 5afef41..9699cf6 100644 --- a/apis/gitlab/v1alpha1/gitlabcredentials_types.go +++ b/apis/gitlab/v1alpha1/gitlabcredentials_types.go @@ -21,24 +21,24 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// GitlabCredentialsSpec defines the desired state of GitlabCredentials, this stores a Gitlab username -// and Access Token for communicating with the Gitlab API. -type GitlabCredentialsSpec struct { +// GitLabCredentialsSpec defines the desired state of GitLabCredentials, this stores a GitLab username +// and Access Token for communicating with the GitLab API. +type GitLabCredentialsSpec struct { // URL is the url for the GitLab API that will be contacted. URL string `json:"url,omitempty"` - // Username is the Gitlab username for the account that will be communicating with the Gitlab API + // Username is the GitLab username for the account that will be communicating with the GitLab API Username string `json:"username,omitempty"` - //AccessToken is the SecretRef to the secret containing the Gitlab Access Token for the user. + //AccessToken is the SecretRef to the secret containing the GitLab Access Token for the user. AccessToken v1.SecretReference `json:"accessToken,omitempty"` - //AccessTokenKey is the key of the secret data that contains the Gitlab Access Token for the user. + //AccessTokenKey is the key of the secret data that contains the GitLab Access Token for the user. AccessTokenKey string `json:"accessTokenKey"` } -// GitlabCredentialsStatus defines the observed state of GitlabCredentials -type GitlabCredentialsStatus struct { +// GitLabCredentialsStatus defines the observed state of GitLabCredentials +type GitLabCredentialsStatus struct { // LastUsedTime is the time that this credential was last used to access a GitLab API LastUsedDate metav1.Time `json:"lastUsedDate"` } @@ -46,24 +46,24 @@ type GitlabCredentialsStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// GitlabCredentials is the Schema for the gitlabcredentials API -type GitlabCredentials struct { +// GitLabCredentials is the Schema for the gitlabcredentials API +type GitLabCredentials struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec GitlabCredentialsSpec `json:"spec,omitempty"` - Status GitlabCredentialsStatus `json:"status,omitempty"` + Spec GitLabCredentialsSpec `json:"spec,omitempty"` + Status GitLabCredentialsStatus `json:"status,omitempty"` } //+kubebuilder:object:root=true -// GitlabCredentialsList contains a list of GitlabCredentials -type GitlabCredentialsList struct { +// GitLabCredentialsList contains a list of GitLabCredentials +type GitLabCredentialsList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []GitlabCredentials `json:"items"` + Items []GitLabCredentials `json:"items"` } func init() { - SchemeBuilder.Register(&GitlabCredentials{}, &GitlabCredentialsList{}) + SchemeBuilder.Register(&GitLabCredentials{}, &GitLabCredentialsList{}) } diff --git a/apis/gitlab/v1alpha1/gitlabcredentials_types_test.go b/apis/gitlab/v1alpha1/gitlabcredentials_types_test.go index 0fd49df..6bdf862 100755 --- a/apis/gitlab/v1alpha1/gitlabcredentials_types_test.go +++ b/apis/gitlab/v1alpha1/gitlabcredentials_types_test.go @@ -12,7 +12,7 @@ import ( ) // Reusable test variables -type testVarsGitlabcredentials = struct { +type testVarsGitLabcredentials = struct { testKind string testApiversion string testSpec string @@ -23,24 +23,24 @@ type testVarsGitlabcredentials = struct { expectedSpec string expectedStatus string - testObject1 GitlabCredentials - testObject2 GitlabCredentials + testObject1 GitLabCredentials + testObject2 GitLabCredentials - objectItems1 []GitlabCredentials - objectList1 GitlabCredentialsList + objectItems1 []GitLabCredentials + objectList1 GitLabCredentialsList - objectItems2 []GitlabCredentials - objectList2 GitlabCredentialsList + objectItems2 []GitLabCredentials + objectList2 GitLabCredentialsList - testObjectSpec1 GitlabCredentialsSpec - testObjectSpec2 GitlabCredentialsSpec + testObjectSpec1 GitLabCredentialsSpec + testObjectSpec2 GitLabCredentialsSpec - testObjectStatus1 GitlabCredentialsStatus - testObjectStatus2 GitlabCredentialsStatus + testObjectStatus1 GitLabCredentialsStatus + testObjectStatus2 GitLabCredentialsStatus } -func initVarsGitlabCredentials() testVarsGitlabcredentials { - testVars := testVarsGitlabcredentials{} +func initVarsGitLabCredentials() testVarsGitLabcredentials { + testVars := testVarsGitLabcredentials{} testVars.testKind = "TestKind" testVars.testApiversion = "v22" @@ -53,27 +53,27 @@ func initVarsGitlabCredentials() testVarsGitlabcredentials { testVars.expectedStatus = testVars.testStatus var object1Metatype metav1.TypeMeta = metav1.TypeMeta{Kind: testVars.testKind, APIVersion: testVars.testApiversion} - testVars.testObject1 = GitlabCredentials{TypeMeta: object1Metatype} + testVars.testObject1 = GitLabCredentials{TypeMeta: object1Metatype} var object2Metatype metav1.TypeMeta = metav1.TypeMeta{Kind: "TestKind2", APIVersion: "V99"} - testVars.testObject2 = GitlabCredentials{TypeMeta: object2Metatype} + testVars.testObject2 = GitLabCredentials{TypeMeta: object2Metatype} var objectList1Metatype metav1.TypeMeta = metav1.TypeMeta{Kind: "TestKind_List", APIVersion: "V12"} - var objectItems1 []GitlabCredentials = []GitlabCredentials{testVars.testObject1, testVars.testObject2} - testVars.objectList1 = GitlabCredentialsList{TypeMeta: objectList1Metatype, Items: objectItems1} + var objectItems1 []GitLabCredentials = []GitLabCredentials{testVars.testObject1, testVars.testObject2} + testVars.objectList1 = GitLabCredentialsList{TypeMeta: objectList1Metatype, Items: objectItems1} var objectList2Metatype metav1.TypeMeta = metav1.TypeMeta{Kind: "TestKind_List", APIVersion: "V12"} - var objectItems2 []GitlabCredentials = []GitlabCredentials{testVars.testObject2} - testVars.objectList2 = GitlabCredentialsList{TypeMeta: objectList2Metatype, Items: objectItems2} + var objectItems2 []GitLabCredentials = []GitLabCredentials{testVars.testObject2} + testVars.objectList2 = GitLabCredentialsList{TypeMeta: objectList2Metatype, Items: objectItems2} - testVars.testObjectSpec1 = GitlabCredentialsSpec{ + testVars.testObjectSpec1 = GitLabCredentialsSpec{ URL: "https://example1.com", Username: "", AccessToken: v1.SecretReference{ Name: "mySecret", Namespace: "aNamespace", }} - testVars.testObjectSpec2 = GitlabCredentialsSpec{ + testVars.testObjectSpec2 = GitLabCredentialsSpec{ URL: "https://example.com", Username: "user2", AccessToken: v1.SecretReference{ @@ -83,12 +83,12 @@ func initVarsGitlabCredentials() testVarsGitlabcredentials { } // leave scaffold Foo value for testing? - testVars.testObjectStatus1 = GitlabCredentialsStatus{ + testVars.testObjectStatus1 = GitLabCredentialsStatus{ LastUsedDate: metav1.Time{ Time: time.Now(), }, } - testVars.testObjectStatus2 = GitlabCredentialsStatus{ + testVars.testObjectStatus2 = GitLabCredentialsStatus{ LastUsedDate: metav1.Time{ Time: time.Now(), }, @@ -97,7 +97,7 @@ func initVarsGitlabCredentials() testVarsGitlabcredentials { return testVars } -func TestGroupVars_GitlabCredentials(t *testing.T) { +func TestGroupVars_GitLabCredentials(t *testing.T) { xType := reflect.TypeOf(GroupVersion) // convert object type to string @@ -110,9 +110,9 @@ func TestGroupVars_GitlabCredentials(t *testing.T) { t.Log("Success") } -// Test Type called GitlabCredentials -func TestTypes_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +// Test Type called GitLabCredentials +func TestTypes_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() want := testVariables.expectedApiversion got := testVariables.testObject1.APIVersion @@ -123,8 +123,8 @@ func TestTypes_GitlabCredentials(t *testing.T) { } // DeepCopy -func TestDeepCopy_DeepCopy_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopy_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() newObject := testVariables.testObject1.DeepCopy() @@ -144,7 +144,7 @@ func TestDeepCopy_DeepCopy_GitlabCredentials(t *testing.T) { t.Errorf("got %s want %s", got, want) } - var nilTestPtr *GitlabCredentials = nil + var nilTestPtr *GitLabCredentials = nil var val = nilTestPtr.DeepCopyObject() if val != nil { t.Errorf("got %s want %s", "not nil", "nil") @@ -153,8 +153,8 @@ func TestDeepCopy_DeepCopy_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopyInto_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyInto_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() testVariables.testObject1.DeepCopyInto(&testVariables.testObject2) @@ -167,11 +167,11 @@ func TestDeepCopy_DeepCopyInto_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopyObject_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyObject_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() newRuntimeObject := testVariables.testObject1.DeepCopyObject() - newObject := newRuntimeObject.(*GitlabCredentials) + newObject := newRuntimeObject.(*GitLabCredentials) got := newObject.APIVersion want := testVariables.expectedApiversion @@ -181,8 +181,8 @@ func TestDeepCopy_DeepCopyObject_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopyList_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyList_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() newObjectList := testVariables.objectList1.DeepCopy() got := newObjectList.Items[0].APIVersion @@ -193,7 +193,7 @@ func TestDeepCopy_DeepCopyList_GitlabCredentials(t *testing.T) { } // a typed pointer set to nil - var nilTestPtr *GitlabCredentialsList = nil + var nilTestPtr *GitLabCredentialsList = nil var val = nilTestPtr.DeepCopy() if val != nil { t.Errorf("got %s want %s", "not nil", "nil") @@ -201,8 +201,8 @@ func TestDeepCopy_DeepCopyList_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopyIntoList_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyIntoList_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() testVariables.objectList1.DeepCopyInto(&testVariables.objectList2) @@ -215,11 +215,11 @@ func TestDeepCopy_DeepCopyIntoList_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopyListObject_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyListObject_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() newRuntimeObject := testVariables.objectList1.DeepCopyObject() - newObject := newRuntimeObject.(*GitlabCredentialsList) + newObject := newRuntimeObject.(*GitLabCredentialsList) got := newObject.Items[0].APIVersion want := testVariables.expectedApiversion @@ -227,7 +227,7 @@ func TestDeepCopy_DeepCopyListObject_GitlabCredentials(t *testing.T) { t.Errorf("got %s want %s", got, want) } - var nilTestPtr *GitlabCredentialsList = nil + var nilTestPtr *GitLabCredentialsList = nil var val = nilTestPtr.DeepCopyObject() if val != nil { t.Errorf("got %s want %s", "not nil", "nil") @@ -236,8 +236,8 @@ func TestDeepCopy_DeepCopyListObject_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopySpec_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopySpec_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() newObjectList := testVariables.testObjectSpec1.DeepCopy() @@ -245,7 +245,7 @@ func TestDeepCopy_DeepCopySpec_GitlabCredentials(t *testing.T) { Expect(newObjectList).To(Equal(testVariables.testObjectSpec1)) }) - var nilTestPtr *GitlabCredentialsSpec = nil + var nilTestPtr *GitLabCredentialsSpec = nil var val = nilTestPtr.DeepCopy() if val != nil { t.Errorf("got %s want %s", "not nil", "nil") @@ -253,8 +253,8 @@ func TestDeepCopy_DeepCopySpec_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopySpecInto_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopySpecInto_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() testVariables.testObjectSpec1.DeepCopyInto(&testVariables.testObjectSpec2) @@ -263,8 +263,8 @@ func TestDeepCopy_DeepCopySpecInto_GitlabCredentials(t *testing.T) { }) } -func TestDeepCopy_DeepCopyStatus_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyStatus_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() newObjectStatus := testVariables.testObjectStatus1.DeepCopy() @@ -273,7 +273,7 @@ func TestDeepCopy_DeepCopyStatus_GitlabCredentials(t *testing.T) { }) // a typed pointer set to nil - var nilTestPtr *GitlabCredentialsStatus = nil + var nilTestPtr *GitLabCredentialsStatus = nil var val = nilTestPtr.DeepCopy() if val != nil { t.Errorf("got %s want %s", "not nil", "nil") @@ -282,8 +282,8 @@ func TestDeepCopy_DeepCopyStatus_GitlabCredentials(t *testing.T) { t.Log("Success") } -func TestDeepCopy_DeepCopyStatusInto_GitlabCredentials(t *testing.T) { - testVariables := initVarsGitlabCredentials() +func TestDeepCopy_DeepCopyStatusInto_GitLabCredentials(t *testing.T) { + testVariables := initVarsGitLabCredentials() testVariables.testObjectStatus1.DeepCopyInto(&testVariables.testObjectStatus2) diff --git a/apis/gitlab/v1alpha1/group_types.go b/apis/gitlab/v1alpha1/group_types.go index 002a822..2dc075b 100755 --- a/apis/gitlab/v1alpha1/group_types.go +++ b/apis/gitlab/v1alpha1/group_types.go @@ -26,17 +26,17 @@ type GroupSpec struct { // +kubebuilder:validation:required FullPath string `json:"path"` - // Name is the name of the Group and will be used as part of the URL in Gitlab + // Name is the name of the Group and will be used as part of the URL in GitLab // +kubebuilder:validation:Required Name string `json:"name"` - // Description is the Gitlab Description for the group + // Description is the GitLab Description for the group // +kubebuilder:validation:optional Description string `json:"description"` - // GitlabCredentialsName is the name of the object in this namespace that contains authentication + // GitLabCredentialsName is the name of the object in this namespace that contains authentication // information for logging into the - GitlabCredentialsName string `json:"gitlabCredentialsName"` + GitLabCredentialsName string `json:"gitlabCredentialsName"` // KustomizeProductionPath is the relative path for the kustomization manifest for production use // +kubebuilder:validation:required diff --git a/apis/gitlab/v1alpha1/group_types_test.go b/apis/gitlab/v1alpha1/group_types_test.go index af9ea67..cec7886 100644 --- a/apis/gitlab/v1alpha1/group_types_test.go +++ b/apis/gitlab/v1alpha1/group_types_test.go @@ -69,12 +69,12 @@ func initVarsGroup() testVarsGroup { testVars.testObjectSpec1 = GroupSpec{ Name: "testGroup1", - GitlabCredentialsName: "nameOfTheCredentials", + GitLabCredentialsName: "nameOfTheCredentials", Description: "testDescription1", } testVars.testObjectSpec2 = GroupSpec{ Name: "testGroup2", - GitlabCredentialsName: "nameOfCredentials2", + GitLabCredentialsName: "nameOfCredentials2", ProjectSpecs: nil, Description: "testDescription2", } diff --git a/apis/gitlab/v1alpha1/project_types.go b/apis/gitlab/v1alpha1/project_types.go index 0532dee..54efdca 100755 --- a/apis/gitlab/v1alpha1/project_types.go +++ b/apis/gitlab/v1alpha1/project_types.go @@ -34,9 +34,9 @@ type ProjectSpec struct { // +kubebuilder:validation:required FullPath string `json:"path"` - // GitlabCredentialsName is the name of the object in this namespace that contains authentication + // GitLabCredentialsName is the name of the object in this namespace that contains authentication // information for logging into the - GitlabCredentialsName string `json:"gitlabCredentialsName"` + GitLabCredentialsName string `json:"gitlabCredentialsName"` // ImpactLevel is the RMF Impact Level for this Project // +kubebuilder:validation:Enum=2;4;5;6 @@ -61,6 +61,10 @@ type ProjectSpec struct { // ManifestImage is the name of the DockerImage for the Project application // +kubebuilder:validation:required ManifestImage string `json:"manifestImage"` + + // CiConfigurationPath is the GitLab path to the CI configuration file in the CI/CD Settings of the project + // +kubebuilder:validation:required + CiConfigurationPath string `json:"ciConfigurationPath"` } // ProjectStatus defines the observed state of Project diff --git a/apis/gitlab/v1alpha1/zz_generated.deepcopy.go b/apis/gitlab/v1alpha1/zz_generated.deepcopy.go index d0f9340..8931a55 100644 --- a/apis/gitlab/v1alpha1/zz_generated.deepcopy.go +++ b/apis/gitlab/v1alpha1/zz_generated.deepcopy.go @@ -214,7 +214,7 @@ func (in *DNSRepoMergeRequestStatus) DeepCopy() *DNSRepoMergeRequestStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitlabCredentials) DeepCopyInto(out *GitlabCredentials) { +func (in *GitLabCredentials) DeepCopyInto(out *GitLabCredentials) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -222,18 +222,18 @@ func (in *GitlabCredentials) DeepCopyInto(out *GitlabCredentials) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabCredentials. -func (in *GitlabCredentials) DeepCopy() *GitlabCredentials { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitLabCredentials. +func (in *GitLabCredentials) DeepCopy() *GitLabCredentials { if in == nil { return nil } - out := new(GitlabCredentials) + out := new(GitLabCredentials) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GitlabCredentials) DeepCopyObject() runtime.Object { +func (in *GitLabCredentials) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -241,31 +241,31 @@ func (in *GitlabCredentials) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitlabCredentialsList) DeepCopyInto(out *GitlabCredentialsList) { +func (in *GitLabCredentialsList) DeepCopyInto(out *GitLabCredentialsList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]GitlabCredentials, len(*in)) + *out = make([]GitLabCredentials, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabCredentialsList. -func (in *GitlabCredentialsList) DeepCopy() *GitlabCredentialsList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitLabCredentialsList. +func (in *GitLabCredentialsList) DeepCopy() *GitLabCredentialsList { if in == nil { return nil } - out := new(GitlabCredentialsList) + out := new(GitLabCredentialsList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GitlabCredentialsList) DeepCopyObject() runtime.Object { +func (in *GitLabCredentialsList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -273,33 +273,33 @@ func (in *GitlabCredentialsList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitlabCredentialsSpec) DeepCopyInto(out *GitlabCredentialsSpec) { +func (in *GitLabCredentialsSpec) DeepCopyInto(out *GitLabCredentialsSpec) { *out = *in out.AccessToken = in.AccessToken } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabCredentialsSpec. -func (in *GitlabCredentialsSpec) DeepCopy() *GitlabCredentialsSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitLabCredentialsSpec. +func (in *GitLabCredentialsSpec) DeepCopy() *GitLabCredentialsSpec { if in == nil { return nil } - out := new(GitlabCredentialsSpec) + out := new(GitLabCredentialsSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitlabCredentialsStatus) DeepCopyInto(out *GitlabCredentialsStatus) { +func (in *GitLabCredentialsStatus) DeepCopyInto(out *GitLabCredentialsStatus) { *out = *in in.LastUsedDate.DeepCopyInto(&out.LastUsedDate) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabCredentialsStatus. -func (in *GitlabCredentialsStatus) DeepCopy() *GitlabCredentialsStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitLabCredentialsStatus. +func (in *GitLabCredentialsStatus) DeepCopy() *GitLabCredentialsStatus { if in == nil { return nil } - out := new(GitlabCredentialsStatus) + out := new(GitLabCredentialsStatus) in.DeepCopyInto(out) return out } diff --git a/clients/gitlab/client_test.go b/clients/gitlab/client_test.go index 9cff64a..2b552da 100644 --- a/clients/gitlab/client_test.go +++ b/clients/gitlab/client_test.go @@ -69,7 +69,7 @@ func TestClient_GetUser(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -88,7 +88,7 @@ func TestClient_GetUser(t *testing.T) { }{ { name: "GetUser 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{userID: 1}, want: &testUser, wantErr: false, @@ -134,7 +134,7 @@ func TestClient_GetUserByUsername(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -154,7 +154,7 @@ func TestClient_GetUserByUsername(t *testing.T) { }{ { name: "GetUserBuUsername 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{username: &testUsername}, want: &testUser, want1: http.StatusFound, @@ -162,7 +162,7 @@ func TestClient_GetUserByUsername(t *testing.T) { }, { name: "GetUserBuUsername 2", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{username: &testUsername}, want: nil, want1: http.StatusNotFound, @@ -235,7 +235,7 @@ func TestClient_GetUsers(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -254,21 +254,21 @@ func TestClient_GetUsers(t *testing.T) { }{ { name: "GetUsers 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: nil}, want: testUserArray, wantErr: false, }, { name: "GetUsers 2", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: &search}, want: testUserArray, wantErr: false, }, { name: "GetUsers Empty", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: &testEmptySearch}, want: testEmptyUserArray, wantErr: false, @@ -317,7 +317,7 @@ func TestClient_AddUser(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -337,7 +337,7 @@ func TestClient_AddUser(t *testing.T) { }{ { name: "AddUser 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{createUserOptions: &gogitlab.CreateUserOptions{Name: &testName, Username: &testUsername, Password: &testPassword}}, want: &testUser1, wantErr: false, @@ -381,7 +381,7 @@ func TestClient_UpdateUser(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) updatedName := "Updated Name" type fields struct { @@ -403,7 +403,7 @@ func TestClient_UpdateUser(t *testing.T) { }{ { name: "UpdateUser 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{user: &testUser1, modifyUserOptions: gogitlab.ModifyUserOptions{Name: &updatedName}}, want: &testUser1, wantErr: false, @@ -465,7 +465,7 @@ func TestClient_DeleteUser(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -486,14 +486,14 @@ func TestClient_DeleteUser(t *testing.T) { }{ { name: "DeleteUser Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{userID: testUserID, waitInterval: 1000, waitCount: 10}, want: http.StatusOK, wantErr: false, }, { name: "DeleteUser Timeout", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{userID: testUserID, waitInterval: 1000, waitCount: 1}, want: http.StatusRequestTimeout, wantErr: false, @@ -544,7 +544,7 @@ func TestClient_DeleteUserByUsername(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -563,14 +563,14 @@ func TestClient_DeleteUserByUsername(t *testing.T) { }{ { name: "DeleteUserByUsername Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{username: testUsername}, want: http.StatusAccepted, wantErr: false, }, { name: "DeleteUserByUsername Not Found", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{username: testUsername}, want: http.StatusNotFound, wantErr: false, @@ -634,7 +634,7 @@ func TestClient_GetGroup(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -653,7 +653,7 @@ func TestClient_GetGroup(t *testing.T) { }{ { name: "GetGroup 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{userID: 1}, want: &testGroup, wantErr: false, @@ -708,7 +708,7 @@ func TestClient_GetGroupByFullPath(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -728,7 +728,7 @@ func TestClient_GetGroupByFullPath(t *testing.T) { }{ { name: "GetGroups 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{fullPath: &testFullPath1}, want: &testGroup1, want1: http.StatusFound, @@ -780,7 +780,7 @@ func TestClient_GetGroups(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -799,14 +799,14 @@ func TestClient_GetGroups(t *testing.T) { }{ { name: "GetGroups 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: nil}, want: testGroupArray, wantErr: false, }, { name: "GetGroups 2", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: &search}, want: testGroupArray, wantErr: false, @@ -854,7 +854,7 @@ func TestClient_AddGroup(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -874,7 +874,7 @@ func TestClient_AddGroup(t *testing.T) { }{ { name: "AddGroup 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{createGroupOptions: gogitlab.CreateGroupOptions{Name: &testGroupName}}, want: &testGroup, wantErr: false, @@ -924,7 +924,7 @@ func TestClient_AddGroupMember(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -946,7 +946,7 @@ func TestClient_AddGroupMember(t *testing.T) { }{ { name: "AddGroupMember 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{groupID: &testGroupID, userID: &testUserID, accessLevel: testAccessLevel}, want: &testGroupMember, want1: http.StatusOK, @@ -994,7 +994,7 @@ func TestClient_UpdateGroup(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1015,7 +1015,7 @@ func TestClient_UpdateGroup(t *testing.T) { }{ { name: "UpdateGroup 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{groupID: testGroupID, updateGroupOptions: &gogitlab.UpdateGroupOptions{Name: &testUpdatedName}}, want: &testUpdatedGroup, want1: http.StatusOK, @@ -1075,7 +1075,7 @@ func TestClient_DeleteGroup(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1096,14 +1096,14 @@ func TestClient_DeleteGroup(t *testing.T) { }{ { name: "DeleteGroup Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{groupID: testGroupID, waitInterval: 1000, waitCount: 10}, want: http.StatusOK, wantErr: false, }, { name: "DeleteGroup Timeout", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{groupID: testGroupID, waitInterval: 1000, waitCount: 1}, want: http.StatusRequestTimeout, wantErr: false, @@ -1151,7 +1151,7 @@ func TestClient_GetProject(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1170,7 +1170,7 @@ func TestClient_GetProject(t *testing.T) { }{ { name: "GetGroup 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{projectID: 1}, want: &testProject, wantErr: false, @@ -1216,7 +1216,7 @@ func TestClient_GetProjects(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) // test objects search := "searchstring" @@ -1237,14 +1237,14 @@ func TestClient_GetProjects(t *testing.T) { }{ { name: "GetProjects 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: nil}, want: testProjectArray, wantErr: false, }, { name: "GetProjects 2", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{search: &search}, want: testProjectArray, wantErr: false, @@ -1292,7 +1292,7 @@ func TestClient_GetProjectByFullPath(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1312,7 +1312,7 @@ func TestClient_GetProjectByFullPath(t *testing.T) { }{ { name: "GetProjects 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{fullPath: &testProjectFullPath1}, want: &testProject1, want1: http.StatusFound, @@ -1363,7 +1363,7 @@ func TestClient_AddProject(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1383,7 +1383,7 @@ func TestClient_AddProject(t *testing.T) { }{ { name: "AddGroup 1", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{createProjectOptions: &createTestProjectOptions}, want1: 200, want: &testProject, @@ -1434,7 +1434,7 @@ func TestClient_UpdateProject(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1455,7 +1455,7 @@ func TestClient_UpdateProject(t *testing.T) { }{ { name: "UpdateProject Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{projectID: testProjectID}, want: &testUpdatedProject, want1: http.StatusOK, @@ -1514,7 +1514,7 @@ func TestClient_DeleteProject(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1535,14 +1535,14 @@ func TestClient_DeleteProject(t *testing.T) { }{ { name: "DeleteProject Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{projectID: testProjectID, waitInterval: 1000, waitCount: 10}, want: http.StatusOK, wantErr: false, }, { name: "DeleteProject Timeout", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{projectID: testProjectID, waitInterval: 1000, waitCount: 1}, want: http.StatusRequestTimeout, wantErr: false, @@ -1603,7 +1603,7 @@ func TestClient_GetMergeRequests(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1625,7 +1625,7 @@ func TestClient_GetMergeRequests(t *testing.T) { }{ { name: "UpdateProject Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{projectID: testProjectID, sourceBranch: testSourceBranch, targetBranch: testTargetBranch}, want: testGetMRs, want1: http.StatusOK, @@ -1691,7 +1691,7 @@ func TestClient_CreateMergeRequest(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab Client object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1713,7 +1713,7 @@ func TestClient_CreateMergeRequest(t *testing.T) { }{ { name: "UpdateProject Success", - fields: fields{client: testGitlabClient, token: testToken, apiURL: testAPIUrl}, + fields: fields{client: testGitLabClient, token: testToken, apiURL: testAPIUrl}, args: args{projectID: testProjectID, mrOptions: &gogitlab.CreateMergeRequestOptions{ SourceBranch: &testSourceBranch, TargetBranch: &testTargetBranch, @@ -1790,7 +1790,7 @@ func TestClientImpl_AddGroupVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1813,7 +1813,7 @@ func TestClientImpl_AddGroupVariable(t *testing.T) { { name: "Test Group Variable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -1889,7 +1889,7 @@ func TestClientImpl_UpdateGroupVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -1912,7 +1912,7 @@ func TestClientImpl_UpdateGroupVariable(t *testing.T) { { name: "Test Update Group Variable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -1969,7 +1969,7 @@ func TestClientImpl_DeleteGroupVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client token string @@ -1989,7 +1989,7 @@ func TestClientImpl_DeleteGroupVariable(t *testing.T) { { name: "Test Delete Group Variable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2062,7 +2062,7 @@ func TestClientImpl_AddProjectVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -2085,7 +2085,7 @@ func TestClientImpl_AddProjectVariable(t *testing.T) { { name: "Test Group Variable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2161,7 +2161,7 @@ func TestClientImpl_UpdateProjectVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -2184,7 +2184,7 @@ func TestClientImpl_UpdateProjectVariable(t *testing.T) { { name: "Test UpdateProjectVariable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2241,7 +2241,7 @@ func TestClientImpl_DeleteProjectVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -2262,7 +2262,7 @@ func TestClientImpl_DeleteProjectVariable(t *testing.T) { { name: "Test DeleteProjectVariable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2327,7 +2327,7 @@ func TestClientImpl_GetGroupVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -2349,7 +2349,7 @@ func TestClientImpl_GetGroupVariable(t *testing.T) { { name: "Test GetGroupVariable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2418,7 +2418,7 @@ func TestClientImpl_GetProjectVariable(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client token string @@ -2439,7 +2439,7 @@ func TestClientImpl_GetProjectVariable(t *testing.T) { { name: "Test GetProjectVariable", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2509,7 +2509,7 @@ func TestClientImpl_GetGroupVariables(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client @@ -2530,7 +2530,7 @@ func TestClientImpl_GetGroupVariables(t *testing.T) { { name: "Test GetGroupVariables", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, @@ -2599,7 +2599,7 @@ func TestClientImpl_GetProjectVariables(t *testing.T) { testAPIUrl := "https://test/api/v4/" testToken := "token" // create a gitlab ClientImpl object, inject http client to allow for mocking using httpmock - testGitlabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) + testGitLabClient, _ := gogitlab.NewClient(testToken, gogitlab.WithBaseURL(testAPIUrl), gogitlab.WithHTTPClient(testHTTPClient)) type fields struct { client *gogitlab.Client token string @@ -2620,7 +2620,7 @@ func TestClientImpl_GetProjectVariables(t *testing.T) { { name: "Test GetProjectVariables", fields: fields{ - client: testGitlabClient, + client: testGitLabClient, token: testToken, apiURL: testAPIUrl, }, diff --git a/config/crd/bases/gitlab.valkyrie.dso.mil_dnsrepocredentials.yaml b/config/crd/bases/gitlab.valkyrie.dso.mil_dnsrepocredentials.yaml index 45b6059..41d1223 100644 --- a/config/crd/bases/gitlab.valkyrie.dso.mil_dnsrepocredentials.yaml +++ b/config/crd/bases/gitlab.valkyrie.dso.mil_dnsrepocredentials.yaml @@ -37,8 +37,8 @@ spec: description: DNSRepoCredentialSpec defines the desired state of DNSRepoCredential properties: gitlabProjectId: - description: GitlabProjectID is the project ID of the DNS project - in Gitlab + description: GitLabProjectID is the project ID of the DNS project + in GitLab type: integer repoUrl: description: 'RepoURL is the url for the DNS git repository. For example: diff --git a/config/crd/bases/gitlab.valkyrie.dso.mil_gitlabcredentials.yaml b/config/crd/bases/gitlab.valkyrie.dso.mil_gitlabcredentials.yaml index 5cb1023..e1dc1a8 100644 --- a/config/crd/bases/gitlab.valkyrie.dso.mil_gitlabcredentials.yaml +++ b/config/crd/bases/gitlab.valkyrie.dso.mil_gitlabcredentials.yaml @@ -10,8 +10,8 @@ metadata: spec: group: gitlab.valkyrie.dso.mil names: - kind: GitlabCredentials - listKind: GitlabCredentialsList + kind: GitLabCredentials + listKind: GitLabCredentialsList plural: gitlabcredentials singular: gitlabcredentials scope: Namespaced @@ -19,7 +19,7 @@ spec: - name: v1alpha1 schema: openAPIV3Schema: - description: GitlabCredentials is the Schema for the gitlabcredentials API + description: GitLabCredentials is the Schema for the gitlabcredentials API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -34,13 +34,13 @@ spec: metadata: type: object spec: - description: GitlabCredentialsSpec defines the desired state of GitlabCredentials, - this stores a Gitlab username and Access Token for communicating with - the Gitlab API. + description: GitLabCredentialsSpec defines the desired state of GitLabCredentials, + this stores a GitLab username and Access Token for communicating with + the GitLab API. properties: accessToken: description: AccessToken is the SecretRef to the secret containing - the Gitlab Access Token for the user. + the GitLab Access Token for the user. properties: name: description: Name is unique within a namespace to reference a @@ -53,20 +53,20 @@ spec: type: object accessTokenKey: description: AccessTokenKey is the key of the secret data that contains - the Gitlab Access Token for the user. + the GitLab Access Token for the user. type: string url: description: URL is the url for the GitLab API that will be contacted. type: string username: - description: Username is the Gitlab username for the account that - will be communicating with the Gitlab API + description: Username is the GitLab username for the account that + will be communicating with the GitLab API type: string required: - accessTokenKey type: object status: - description: GitlabCredentialsStatus defines the observed state of GitlabCredentials + description: GitLabCredentialsStatus defines the observed state of GitLabCredentials properties: lastUsedDate: description: LastUsedTime is the time that this credential was last diff --git a/config/crd/bases/gitlab.valkyrie.dso.mil_groups.yaml b/config/crd/bases/gitlab.valkyrie.dso.mil_groups.yaml index 92a7483..a8e74ab 100644 --- a/config/crd/bases/gitlab.valkyrie.dso.mil_groups.yaml +++ b/config/crd/bases/gitlab.valkyrie.dso.mil_groups.yaml @@ -37,10 +37,10 @@ spec: description: GroupSpec defines the desired state of Group properties: description: - description: Description is the Gitlab Description for the group + description: Description is the GitLab Description for the group type: string gitlabCredentialsName: - description: GitlabCredentialsName is the name of the object in this + description: GitLabCredentialsName is the name of the object in this namespace that contains authentication information for logging into the type: string @@ -58,7 +58,7 @@ spec: type: string name: description: Name is the name of the Group and will be used as part - of the URL in Gitlab + of the URL in GitLab type: string path: description: FullPath is the gitlab path for this Project @@ -70,8 +70,12 @@ spec: items: description: ProjectSpec defines the desired state of Project properties: + ciConfigurationPath: + description: CiConfigurationPath is the GitLab path to the CI + configuration file in the CI/CD Settings of the project + type: string gitlabCredentialsName: - description: GitlabCredentialsName is the name of the object + description: GitLabCredentialsName is the name of the object in this namespace that contains authentication information for logging into the type: string @@ -118,6 +122,7 @@ spec: will be created for this Project type: string required: + - ciConfigurationPath - gitlabCredentialsName - groupId - impactLevel diff --git a/config/crd/bases/gitlab.valkyrie.dso.mil_projects.yaml b/config/crd/bases/gitlab.valkyrie.dso.mil_projects.yaml index b056ffb..be1f7ba 100644 --- a/config/crd/bases/gitlab.valkyrie.dso.mil_projects.yaml +++ b/config/crd/bases/gitlab.valkyrie.dso.mil_projects.yaml @@ -36,8 +36,12 @@ spec: spec: description: ProjectSpec defines the desired state of Project properties: + ciConfigurationPath: + description: CiConfigurationPath is the GitLab path to the CI configuration + file in the CI/CD Settings of the project + type: string gitlabCredentialsName: - description: GitlabCredentialsName is the name of the object in this + description: GitLabCredentialsName is the name of the object in this namespace that contains authentication information for logging into the type: string @@ -84,6 +88,7 @@ spec: be created for this Project type: string required: + - ciConfigurationPath - gitlabCredentialsName - groupId - impactLevel diff --git a/config/samples/gitlab_v1alpha1_gitlabcredentials.yaml b/config/samples/gitlab_v1alpha1_gitlabcredentials.yaml index d70ac54..2c0fa40 100644 --- a/config/samples/gitlab_v1alpha1_gitlabcredentials.yaml +++ b/config/samples/gitlab_v1alpha1_gitlabcredentials.yaml @@ -7,7 +7,7 @@ data: accesstoken: cGFzc3dvcmQ= --- apiVersion: gitlab.valkyrie.dso.mil/v1alpha1 -kind: GitlabCredentials +kind: GitLabCredentials metadata: name: gitlab-credentials namespace: default diff --git a/controllers/gitlab/dnsrepomergerequest_controller.go b/controllers/gitlab/dnsrepomergerequest_controller.go index c690068..fa43cda 100644 --- a/controllers/gitlab/dnsrepomergerequest_controller.go +++ b/controllers/gitlab/dnsrepomergerequest_controller.go @@ -105,10 +105,10 @@ func (r *DNSRepoMergeRequestReconciler) Reconcile(ctx context.Context, req ctrl. } repoURL := credential.Spec.RepoURL - projectID := credential.Spec.GitlabProjectID + projectID := credential.Spec.GitLabProjectID - //create Gitlab client for API calls - gitlabAPIURL := getGitlabAPIURL(repoURL) + //create GitLab client for API calls + gitlabAPIURL := getGitLabAPIURL(repoURL) var gitlabClient gitlab.Client if r.gitlabTestClient != nil { gitlabClient = r.gitlabTestClient @@ -222,7 +222,7 @@ func cleanUpOldResources(dnsMergeRequest gitlabv1alpha1.DNSRepoMergeRequest, log //example input: https://code.il2.dso.mil/platform-one/products/valkyrie/dso-dns.git //example output: https://code.il2.dso.mil/api/v4 -func getGitlabAPIURL(repoURL string) string { +func getGitLabAPIURL(repoURL string) string { subs := strings.Split(repoURL, "/") return subs[0] + "/" + subs[1] + "/" + subs[2] + "/api/v4" } diff --git a/controllers/gitlab/dnsrepomergerequest_controller_test.go b/controllers/gitlab/dnsrepomergerequest_controller_test.go index ed3146f..c85d2fe 100644 --- a/controllers/gitlab/dnsrepomergerequest_controller_test.go +++ b/controllers/gitlab/dnsrepomergerequest_controller_test.go @@ -128,7 +128,7 @@ var _ = Describe("Reconcile", func() { ObjectMeta: metav1.ObjectMeta{}, Spec: gitlabv1alpha1.DNSRepoCredentialSpec{ RepoURL: "https://test", - GitlabProjectID: 4148, + GitLabProjectID: 4148, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secretName"}, Key: "username", @@ -198,7 +198,7 @@ var _ = Describe("Reconcile", func() { ObjectMeta: metav1.ObjectMeta{}, Spec: gitlabv1alpha1.DNSRepoCredentialSpec{ RepoURL: "https://test", - GitlabProjectID: 4148, + GitLabProjectID: 4148, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secretName"}, Key: "username", @@ -246,7 +246,7 @@ var _ = Describe("Reconcile", func() { Name: repoCred.Spec.UsernameSecRef.Name, }] = &secret - sut.gitlabTestClient = &MockGitlabClient{ + sut.gitlabTestClient = &MockGitLabClient{ getMRByIDFunc: func(projectID int, mrID int) (*gitlab.MergeRequest, error) { return &gitlab.MergeRequest{ ProjectID: projectID, @@ -307,7 +307,7 @@ var _ = Describe("Reconcile", func() { ObjectMeta: metav1.ObjectMeta{}, Spec: gitlabv1alpha1.DNSRepoCredentialSpec{ RepoURL: "https://test", - GitlabProjectID: 4148, + GitLabProjectID: 4148, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secretName"}, Key: "username", @@ -359,7 +359,7 @@ var _ = Describe("Reconcile", func() { Name: repoCred.Spec.UsernameSecRef.Name, }] = &secret - sut.gitlabTestClient = &MockGitlabClient{ + sut.gitlabTestClient = &MockGitLabClient{ getMRByIDFunc: func(projectID int, mrID int) (*gitlab.MergeRequest, error) { return &gitlab.MergeRequest{ ProjectID: projectID, @@ -416,7 +416,7 @@ var _ = Describe("Reconcile", func() { ObjectMeta: metav1.ObjectMeta{}, Spec: gitlabv1alpha1.DNSRepoCredentialSpec{ RepoURL: "https://test", - GitlabProjectID: 4148, + GitLabProjectID: 4148, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secretName"}, Key: "username", @@ -468,7 +468,7 @@ var _ = Describe("Reconcile", func() { Name: repoCred.Spec.UsernameSecRef.Name, }] = &secret - sut.gitlabTestClient = &MockGitlabClient{ + sut.gitlabTestClient = &MockGitLabClient{ getMRByIDFunc: func(projectID int, mrID int) (*gitlab.MergeRequest, error) { return &gitlab.MergeRequest{ ProjectID: projectID, @@ -578,7 +578,7 @@ var _ = Describe("Reconcile", func() { ObjectMeta: metav1.ObjectMeta{}, Spec: gitlabv1alpha1.DNSRepoCredentialSpec{ RepoURL: "https://test", - GitlabProjectID: 4148, + GitLabProjectID: 4148, UsernameSecRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{Name: "secretName"}, Key: "username", @@ -630,7 +630,7 @@ var _ = Describe("Reconcile", func() { Name: repoCred.Spec.UsernameSecRef.Name, }] = &secret - sut.gitlabTestClient = &MockGitlabClient{ + sut.gitlabTestClient = &MockGitLabClient{ getMRByIDFunc: func(projectID int, mrID int) (*gitlab.MergeRequest, error) { return &gitlab.MergeRequest{ ProjectID: projectID, diff --git a/controllers/gitlab/gitlabcredentials_controller.go b/controllers/gitlab/gitlabcredentials_controller.go index 670200a..7f8499a 100644 --- a/controllers/gitlab/gitlabcredentials_controller.go +++ b/controllers/gitlab/gitlabcredentials_controller.go @@ -27,7 +27,7 @@ import ( gitlabv1alpha1 "valkyrie.dso.mil/valkyrie-api/apis/gitlab/v1alpha1" ) -// CredentialsReconciler reconciles a GitlabCredentials object +// CredentialsReconciler reconciles a GitLabCredentials object type CredentialsReconciler struct { client.Client Log logr.Logger @@ -52,6 +52,6 @@ func (r *CredentialsReconciler) Reconcile(ctx context.Context, req ctrl.Request) // SetupWithManager sets up the controller with the Manager. func (r *CredentialsReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&gitlabv1alpha1.GitlabCredentials{}). + For(&gitlabv1alpha1.GitLabCredentials{}). Complete(r) } diff --git a/controllers/gitlab/gitlabcredentials_controller_test.go b/controllers/gitlab/gitlabcredentials_controller_test.go index eddd2b3..8f0d824 100755 --- a/controllers/gitlab/gitlabcredentials_controller_test.go +++ b/controllers/gitlab/gitlabcredentials_controller_test.go @@ -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, diff --git a/controllers/gitlab/group_controller.go b/controllers/gitlab/group_controller.go index 0e37aa7..12ad4b1 100644 --- a/controllers/gitlab/group_controller.go +++ b/controllers/gitlab/group_controller.go @@ -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,18 @@ 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" ) // Group Status @@ -66,14 +66,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 +86,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 +105,14 @@ 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) return ctrl.Result{Requeue: true}, err } } @@ -127,18 +127,18 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl if !found { 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 } } else { 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 } } 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 } @@ -317,11 +317,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 { diff --git a/controllers/gitlab/group_controller_test.go b/controllers/gitlab/group_controller_test.go index 7937de9..f52105e 100755 --- a/controllers/gitlab/group_controller_test.go +++ b/controllers/gitlab/group_controller_test.go @@ -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{ @@ -196,7 +196,7 @@ var _ = Describe("Reconcile", func() { 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 }, @@ -221,7 +221,7 @@ var _ = Describe("Reconcile", func() { 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,7 +241,7 @@ 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()) @@ -262,7 +262,7 @@ 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()) @@ -276,7 +276,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})) @@ -293,7 +293,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})) @@ -310,7 +310,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})) diff --git a/controllers/gitlab/mocks_test.go b/controllers/gitlab/mocks_test.go index 0c1393f..c446893 100755 --- a/controllers/gitlab/mocks_test.go +++ b/controllers/gitlab/mocks_test.go @@ -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) diff --git a/controllers/gitlab/project_controller.go b/controllers/gitlab/project_controller.go index 9346194..3616d38 100644 --- a/controllers/gitlab/project_controller.go +++ b/controllers/gitlab/project_controller.go @@ -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,21 +67,7 @@ const ManifestImageVariableName = "MANIFEST_IMAGE" const annotationKeyID = "ID" -// Setup General Pipelines -// 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. +// 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) @@ -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 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) + 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 } @@ -122,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); 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 } @@ -183,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 @@ -210,12 +196,13 @@ 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 createProjectOptions := gitlab.CreateProjectOptions{ - Name: &project.Spec.Name, - Path: &project.Spec.FullPath, + Name: &project.Spec.Name, + Path: &project.Spec.FullPath, + CIConfigPath: &project.Spec.CiConfigurationPath, } if gitLabProject, _, err = r.gitlabClient.AddProject(createProjectOptions); err != nil { return nil, err @@ -224,12 +211,13 @@ func (r *ProjectReconciler) createGitlabProject(project *v1alpha1.Project) (*git 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 err error if gitLabProject, _, err = r.gitlabClient.UpdateProject(id, gitlab.EditProjectOptions{ - Name: &project.Spec.Name, - Path: &project.Spec.FullPath, + Name: &project.Spec.Name, + Path: &project.Spec.FullPath, + CIConfigPath: &project.Spec.CiConfigurationPath, }); err != nil { return nil, err } @@ -264,12 +252,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 } @@ -282,7 +270,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 } diff --git a/controllers/gitlab/project_controller_test.go b/controllers/gitlab/project_controller_test.go index 48372ed..2ea5624 100644 --- a/controllers/gitlab/project_controller_test.go +++ b/controllers/gitlab/project_controller_test.go @@ -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" ) @@ -80,7 +80,7 @@ func getProjectControllerWithMocksInGreenTestState() (ProjectReconciler, *MockMa builder: builder, } - gitlabClient := MockGitlabClient{} + gitlabClient := MockGitLabClient{} sut := ProjectReconciler{ Client: &clientMock, @@ -129,7 +129,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 +144,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 +195,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 +227,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 +288,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 +298,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 +311,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 +334,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 +353,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 +366,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 +473,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 +486,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()) diff --git a/custom/p1/group.go b/custom/p1/group.go index 79721e1..ea32c7f 100644 --- a/custom/p1/group.go +++ b/custom/p1/group.go @@ -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) diff --git a/custom/p1/group_test.go b/custom/p1/group_test.go index 5f90a81..636fe0f 100644 --- a/custom/p1/group_test.go +++ b/custom/p1/group_test.go @@ -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) { diff --git a/custom/p1/project.go b/custom/p1/project.go index 3e96df8..7ca03c9 100644 --- a/custom/p1/project.go +++ b/custom/p1/project.go @@ -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 diff --git a/custom/p1/project_test.go b/custom/p1/project_test.go index e46415d..e787e87 100644 --- a/custom/p1/project_test.go +++ b/custom/p1/project_test.go @@ -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) { diff --git a/custom/p1/types.go b/custom/p1/types.go index 705e692..db8bcd8 100644 --- a/custom/p1/types.go +++ b/custom/p1/types.go @@ -4,8 +4,8 @@ import ( "fmt" ) -// GitlabCredentials - -type GitlabCredentials struct { +// GitLabCredentials - +type GitLabCredentials struct { ServerURL string ServerToken string } diff --git a/custom/p1/utils.go b/custom/p1/utils.go index e73d1a5..2660e96 100644 --- a/custom/p1/utils.go +++ b/custom/p1/utils.go @@ -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") } diff --git a/custom/p1/utils_test.go b/custom/p1/utils_test.go index b687e04..0a05c34 100644 --- a/custom/p1/utils_test.go +++ b/custom/p1/utils_test.go @@ -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) } }) } diff --git a/docs/gitlab/projects/README.ms b/docs/gitlab/projects/README.ms index d1009a2..e54466c 100644 --- a/docs/gitlab/projects/README.ms +++ b/docs/gitlab/projects/README.ms @@ -1,4 +1,4 @@ -## Gitlab Projects +## GitLab Projects ### Reference - https://docs.gitlab.com/ee/api/projects.html diff --git a/docs/path-to-ctf/plan_of_action.md b/docs/path-to-ctf/plan_of_action.md index df30b88..55f434c 100644 --- a/docs/path-to-ctf/plan_of_action.md +++ b/docs/path-to-ctf/plan_of_action.md @@ -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. diff --git a/driver.go b/driver.go index ae1706c..de00143 100755 --- a/driver.go +++ b/driver.go @@ -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{ diff --git a/driver_test.go b/driver_test.go index e59eef2..28a0f04 100755 --- a/driver_test.go +++ b/driver_test.go @@ -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() { diff --git a/integration-tests/custom/p1/p1_groups_test.go b/integration-tests/custom/p1/p1_groups_test.go index e90c129..f4f1829 100644 --- a/integration-tests/custom/p1/p1_groups_test.go +++ b/integration-tests/custom/p1/p1_groups_test.go @@ -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, } diff --git a/integration-tests/custom/p1/p1_projects_test.go b/integration-tests/custom/p1/p1_projects_test.go index a0c08f5..dc3fbc4 100644 --- a/integration-tests/custom/p1/p1_projects_test.go +++ b/integration-tests/custom/p1/p1_projects_test.go @@ -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, // } -- GitLab