jkube icon indicating copy to clipboard operation
jkube copied to clipboard

Add support for specifying `imagePullSecrets` via resource configuration

Open rohanKanojia opened this issue 2 years ago • 10 comments

Component

JKube Kit

Is your enhancement related to a problem? Please describe

This was asked by a user on Gitter chat:

How to configure the generated file to include the imagePullSecrets content in the maven pom file

As a user, If I want to specify imagePullSecrets for Deployment, I need to add them in resource fragment like this:

https://github.com/eclipse/jkube/blob/5dc19d9563adb3c10a2ad1f30e8f404d5ca29ab9/quickstarts/maven/tomee/src/main/jkube/deployment.yaml#L26-L27

This option should also be exposed via controller resource configuration

Describe the solution you'd like

As a user, I want to specify imagePullSecrets in my pom.xml like this:

<configuration>
  <resources> 
    <controller>
      <replicas>2</replicas>
       <imagePullSecrets>
           <imagePullSecret>${env.SECRET1}</imagePullSecret>
       </imagePullSecrets>
    </controller>
  </resources>
</configuration>

so that generated Deployment (or any other controller) contains specified imagePullSecrets

Describe alternatives you've considered

No response

Additional context

No response

rohanKanojia avatar Nov 22 '23 05:11 rohanKanojia

@rohanKanojia @manusa can i work on this?

Devashishbasu avatar Jan 09 '24 12:01 Devashishbasu

@Devashishbasu : This one would be a somewhat medium-level difficulty issue. You just need to add a field to ControllerResourceConfig and PodTemplateHandler would read that. A similar field schedule was added to resource configuration in this PR https://github.com/eclipse/jkube/pull/2012

rohanKanojia avatar Jan 09 '24 12:01 rohanKanojia

@rohanKanojia i have added this code for reading imagePullSecrets in PodTemplateHandler is it okay or i have to modify it? or do i have to add test cases?

 public PodTemplateSpec getPodTemplate(ControllerResourceConfig config) {
        List<String> imagePullSecrets = new ArrayList<>();
        if (config.getImagePullSecrets() != null) {
            for (String secret : config.getImagePullSecrets()) {
                imagePullSecrets.add(new String(secret));
            }
        }
        podTemplateSpec.setImagePullSecrets(imagePullSecrets);


    }

Devashishbasu avatar Jan 11 '24 05:01 Devashishbasu

In order to complete this issue, you need to do this:

  1. Add field List<String> imagePullSecrets in ControllerResourceConfig
  2. Modify ControllerResourceConfigTest to test newly added field
  3. Read this field in PodTemplateHandler's createPodSpec and add to PodSpecBuilder's .withImagePullSecrets
  4. Add test case covering this scenario in PodTemplateHandlerTest
  5. Create a new Gradle Integration test for providing imagePullSecrets via resource configuration
  6. Add documentation for newly added field in _controller_resource_generation

rohanKanojia avatar Jan 11 '24 06:01 rohanKanojia

In order to complete this issue, you need to do this:

  1. Add field List<String> imagePullSecrets in ControllerResourceConfig
  2. Modify ControllerResourceConfigTest to test newly added field
  3. Read this field in PodTemplateHandler's createPodSpec and add to PodSpecBuilder's .withImagePullSecrets
  4. Add test case covering this scenario in PodTemplateHandlerTest
  5. Create a new Gradle Integration test for providing imagePullSecrets via resource configuration
  6. Add documentation for newly added field in _controller_resource_generation

thankyou so much

Devashishbasu avatar Jan 11 '24 06:01 Devashishbasu

Hi @rohanKanojia, I have made all the changes ..how do I test these changes??

Devashishbasu avatar Jan 12 '24 04:01 Devashishbasu

@Devashishbasu : Unit tests added to verify this change should pass.

You can also verify by going to any demo project in quickstarts/maven/ .

  • Add the kubernetes-maven-plugin configuration for imagePullSecrets in pom.xml
  • Change the jkube.version to 1.16-SNAPSHOT
  • run mvn k8s:resource
  • Generated manifest in target/classes/META-INF/jkube/kubernetes.yml should contain imagePullSects as specified in pom.xml configuration

rohanKanojia avatar Jan 12 '24 06:01 rohanKanojia

@Devashishbasu : Unit tests added to verify this change should pass.

You can also verify by going to any demo project in quickstarts/maven/ .

  • Add the kubernetes-maven-plugin configuration for imagePullSecrets in pom.xml
  • Change the jkube.version to 1.16-SNAPSHOT
  • run mvn k8s:resource
  • Generated manifest in target/classes/META-INF/jkube/kubernetes.yml should contain imagePullSects as specified in pom.xml configuration

ok thanks

Devashishbasu avatar Jan 12 '24 06:01 Devashishbasu

Hi @rohanKanojia ...unit tests added to verify my changes have passed and when i am building hello-world from quickstarts/maven using mvn clean install its showing build success ...but when i am trying to run mvn k8s:resource then its showing this error [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.109 s [INFO] Finished at: 2024-01-13T23:02:42+05:30 [INFO] ------------------------------------------------------------------------ [ERROR] No plugin found for prefix 'k8s' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\hp.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

please help

Devashishbasu avatar Jan 13 '24 17:01 Devashishbasu

@Devashishbasu : Which quickstart are you using? I meant running it like this:

# Build project
$ mvn clean install
# Go to quickstart
$ cd quickstarts/maven/spring-boot
# Run kubernetes-maven-plugin
$ mvn k8s:resource -Pkubernetes

rohanKanojia avatar Jan 15 '24 15:01 rohanKanojia

@Devashishbasu : polite ping, are you still working on this issue?

rohanKanojia avatar May 27 '24 10:05 rohanKanojia

@Devashishbasu : polite ping, are you still working on this issue?

Hi rohan , no, I am not working on this issue

Devashishbasu avatar May 27 '24 13:05 Devashishbasu

@rohanKanojia, I am interested in working on this issue. Could you assign it to me?

arman-yekkehkhani avatar May 29 '24 13:05 arman-yekkehkhani

@arman-yekkehkhani : Thanks a lot for showing interest in fixing this issue. I had added some code pointers in https://github.com/eclipse-jkube/jkube/issues/2467#issuecomment-1886383825

If you need any help, Please don't hesitate to contact me on Eclipse JKube Gitter Channel.

rohanKanojia avatar May 29 '24 13:05 rohanKanojia

@arman-yekkehkhani : I see you've started working on this. Could you please create a draft PR?

rohanKanojia avatar Jun 04 '24 16:06 rohanKanojia

@rohanKanojia Hi Rohan, I created the PR. However, I am not sure how to implement the Gradle integration test.

arman-yekkehkhani avatar Jun 05 '24 06:06 arman-yekkehkhani

@arman-yekkehkhani : Could you please take a look at old pull requests for adding gradle integration test? https://github.com/eclipse-jkube/jkube/pull/2533

rohanKanojia avatar Jun 05 '24 07:06 rohanKanojia

@rohanKanojia Thank you so much! I added the integration test. Please have a look at it.

arman-yekkehkhani avatar Jun 05 '24 16:06 arman-yekkehkhani