#2 Add kubernetes-credentials-provider plugin to OperatorPlugins
This commit is contained in:
		
							parent
							
								
									9177fbe802
								
							
						
					
					
						commit
						c170acac1d
					
				|  | @ -44,7 +44,11 @@ func NewRole(meta metav1.ObjectMeta) *v1.Role { | |||
| 				Resources: []string{"pods/log"}, | ||||
| 				Verbs:     []string{getVerb, listVerb, watchVerb}, | ||||
| 			}, | ||||
| 			//TODO get secrets ???
 | ||||
| 			{ | ||||
| 				APIGroups: []string{""}, | ||||
| 				Resources: []string{"secrets"}, | ||||
| 				Verbs:     []string{getVerb, listVerb, watchVerb}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -121,6 +121,11 @@ var BasePluginsMap = map[string][]Plugin{ | |||
| 	Must(New("configuration-as-code:1.7")).String(): { | ||||
| 		Must(New("configuration-as-code-support:1.7")), | ||||
| 	}, | ||||
| 	Must(New("kubernetes-credentials-provider:0.12.1")).String(): { | ||||
| 		Must(New(credentialsPlugin)), | ||||
| 		Must(New(structsPlugin)), | ||||
| 		Must(New(variantPlugin)), | ||||
| 	}, | ||||
| } | ||||
| 
 | ||||
| // BasePlugins returns map of plugins to install by operator
 | ||||
|  |  | |||
|  | @ -33,12 +33,14 @@ func TestConfiguration(t *testing.T) { | |||
| 	numberOfExecutors := 6 | ||||
| 	systemMessage := "Configuration as Code integration works!!!" | ||||
| 	systemMessageEnvName := "SYSTEM_MESSAGE" | ||||
| 	jenkinsCredentialName := "kubernetes-credentials-provider-plugin" | ||||
| 
 | ||||
| 	// base
 | ||||
| 	createUserConfigurationSecret(t, jenkinsCRName, namespace, systemMessageEnvName, systemMessage) | ||||
| 	createUserConfigurationConfigMap(t, jenkinsCRName, namespace, numberOfExecutors, fmt.Sprintf("${%s}", systemMessageEnvName)) | ||||
| 	jenkins := createJenkinsCR(t, jenkinsCRName, namespace) | ||||
| 	createDefaultLimitsForContainersInNamespace(t, namespace) | ||||
| 	createKubernetesCredentialsProviderSecret(t, namespace, jenkinsCredentialName) | ||||
| 	waitForJenkinsBaseConfigurationToComplete(t, jenkins) | ||||
| 
 | ||||
| 	verifyJenkinsMasterPodAttributes(t, jenkins) | ||||
|  | @ -49,6 +51,7 @@ func TestConfiguration(t *testing.T) { | |||
| 	waitForJenkinsUserConfigurationToComplete(t, jenkins) | ||||
| 	verifyJenkinsSeedJobs(t, client, jenkins) | ||||
| 	verifyUserConfiguration(t, client, numberOfExecutors, systemMessage) | ||||
| 	verifyIfJenkinsCredentialExists(t, client, jenkinsCredentialName) | ||||
| } | ||||
| 
 | ||||
| func createUserConfigurationSecret(t *testing.T, jenkinsCRName string, namespace string, systemMessageEnvName, systemMessage string) { | ||||
|  | @ -68,6 +71,30 @@ func createUserConfigurationSecret(t *testing.T, jenkinsCRName string, namespace | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func createKubernetesCredentialsProviderSecret(t *testing.T, namespace, name string) { | ||||
| 	secret := &corev1.Secret{ | ||||
| 		ObjectMeta: metav1.ObjectMeta{ | ||||
| 			Name:      name, | ||||
| 			Namespace: namespace, | ||||
| 			Annotations: map[string]string{ | ||||
| 				"jenkins.io/credentials-description": "credentials from Kubernetes", | ||||
| 			}, | ||||
| 			Labels: map[string]string{ | ||||
| 				"jenkins.io/credentials-type": "usernamePassword", | ||||
| 			}, | ||||
| 		}, | ||||
| 		StringData: map[string]string{ | ||||
| 			"username": "user", | ||||
| 			"password": "pass", | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	t.Logf("Secret for Kubernetes credentials provider plugin %+v", *secret) | ||||
| 	if err := framework.Global.Client.Create(context.TODO(), secret, nil); err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func createUserConfigurationConfigMap(t *testing.T, jenkinsCRName string, namespace string, numberOfExecutors int, systemMessage string) { | ||||
| 	userConfiguration := &corev1.ConfigMap{ | ||||
| 		ObjectMeta: metav1.ObjectMeta{ | ||||
|  | @ -248,3 +275,32 @@ if (!"%s".equals(Jenkins.instance.systemMessage)) { | |||
| 	logs, err = jenkinsClient.ExecuteScript(checkConfigurationAsCode) | ||||
| 	assert.NoError(t, err, logs) | ||||
| } | ||||
| 
 | ||||
| func verifyIfJenkinsCredentialExists(t *testing.T, jenkinsClient jenkinsclient.Jenkins, credentialName string) { | ||||
| 	groovyScriptFmt := `import com.cloudbees.plugins.credentials.Credentials | ||||
| 
 | ||||
| Set<Credentials> allCredentials = new HashSet<Credentials>(); | ||||
| 
 | ||||
| def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | ||||
| 	com.cloudbees.plugins.credentials.Credentials.class | ||||
| ); | ||||
| 
 | ||||
| allCredentials.addAll(creds) | ||||
| 
 | ||||
| Jenkins.instance.getAllItems(com.cloudbees.hudson.plugins.folder.Folder.class).each{ f -> | ||||
| 	creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | ||||
|       	com.cloudbees.plugins.credentials.Credentials.class, f) | ||||
| 	allCredentials.addAll(creds) | ||||
| } | ||||
| 
 | ||||
| def found = false | ||||
| for (c in allCredentials) { | ||||
| 	if("%s".equals(c.id)) found = true | ||||
| } | ||||
| if(!found) { | ||||
| 	throw new Exception("Expected credential not found") | ||||
| }` | ||||
| 	groovyScript := fmt.Sprintf(groovyScriptFmt, credentialName) | ||||
| 	logs, err := jenkinsClient.ExecuteScript(groovyScript) | ||||
| 	assert.NoError(t, err, logs) | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue