Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to perform kubernetes build in "odo deploy" using Kaniko build strategy #3751

Conversation

jaideepr97
Copy link

@jaideepr97 jaideepr97 commented Aug 12, 2020

What type of PR is this?

/kind feature

What does does this PR do / why we need it:

This PR extends the current implementation of odo deploy to make it kubernetes generic and allow performing unprivileged builds

  • Adds support for performing kaniko builds in odo deploy and pushing the built image to either an external registry or internal registry
  • Adds support for pushing images built using default BuildConfig path to external registries
  • Adds an optional dockerconfigjson flag to pass reference to a config.json file

NOTE: This PR builds on top of work contained in #3478 , and must only be merged after #3478 has been merged

Which issue(s) this PR fixes:

Fixes #3583

PR acceptance criteria:

  • Unit test

How to test changes / Special notes to the reviewer:

  • create a new directory, cd into it and run odo create nodejs --starter=nodejs-starter
  • run odo url create
  • replace created devfile with the following sample :
schemaVersion: 2.1.0
metadata:
  name: nodejs
  version: 1.0.0
  alpha.deployment-manifest: "https://raw.githubusercontent.com/groeges/devfile-registry/master/devfiles/nodejs/deploy_deployment.yaml"
projects:
  - name: nodejs-starter
    git:
      location: "https://github.com/odo-devfiles/nodejs-ex.git"
components:
  - container:
      name: runtime
      image: registry.access.redhat.com/ubi8/nodejs-12:1-36
      memoryLimit: 1024Mi
      mountSources: true
      endpoints:
        - name: http-3000
          targetPort: 3000
          configuration:
            protocol: tcp
            scheme: http
            type: terminal

  - dockerfile:
      name: dockerfile-build
      source: 
         sourceDir: "src"
         location: "https://github.com/ranakan19/golang-ex.git"
      dockerfileLocation: "https://raw.githubusercontent.com/jaideepr97/OpenShift-guides/master/Dockerfile"
      destination:
      Rootless: true 
    
commands:
  - exec:
      id: install
      component: runtime
      commandLine: npm install
      workingDir: /project
      group:
        kind: build
        isDefault: true
  - exec:
      id: run
      component: runtime
      commandLine: npm start
      workingDir: /project
      group:
        kind: run
        isDefault: true
  - exec:
      id: debug
      component: runtime
      commandLine: npm run debug
      workingDir: /project
      group:
        kind: debug
        isDefault: true
  - exec:
      id: test
      component: runtime
      commandLine: npm test
      workingDir: /project
      group:
        kind: test
        isDefault: true
  • run odo deploy --tag=<imageTag>

NOTE: setting Rootless: true will trigger a kaniko build. The default value is false and will trigger a build using buildConfig

NOTE: Please supply complete destination under --tag
( for ex: image-registry.openshift-image-registry.svc:5000/namespace/imagestream or docker.io/username/repository-name)

NOTE: (Relevant to external registry push only) if --dockerconfigjson is not specified, config.json is picked up from ~/.docker. Please ensure the default config.json file contains a valid auth token. External registry push is currently only configured for Dockerhub

EnriqueL8 and others added 30 commits June 4, 2020 14:39
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
 - Downloads Dockerfile into memory rather than onto the hosts machine
 - Validates if a Dockerfile is present in the project source, if one isn't specified by the devfile
 - Validates the contents of the Dockerfile (that there is a FROM on the first non-comment/non-whitespace line)
 - Validates the tag passed as an arg conforms to the correct character-set
 - Copies all project source files into the container rather than new/updated
 - Additional Testing
 - More appropriate error/warning messages
Co-authored-by: Cameron McWilliam <cam.mcwilliam@me.com>
* Add test List URL function

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>

* Update logging within maifest deploy

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>

* Add preliminary support for multiple manifest in single yaml

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>

* Update service manifest with ClusterIP value before update.

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>

* Merge deployDelete code and update to support multiple doc in yaml

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>

* Fix source formatting

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>

* Add some extra checks on waitManifestDeployComplete function

Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
alpha.deployment-manifest


Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
* Remove CommonPushOptions and do some clean up

* Move validation, add better user experience, remove devfile.yaml flag
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign dharmit
You can assign the PR to them by writing /assign @dharmit in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. Required by Prow. label Aug 12, 2020
@openshift-ci-robot
Copy link
Collaborator

Hi @jaideepr97. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jaideepr97
Copy link
Author

jaideepr97 commented Aug 12, 2020

@jaideepr97 jaideepr97 changed the title Add support to perform kaniko build in "odo deploy" Add support to perform kubernetes build in "odo deploy" using Kaniko build strategy Aug 12, 2020
@amitkrout
Copy link
Contributor

/ok-to-test

@openshift-ci-robot openshift-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. Required by Prow. labels Aug 13, 2020
@openshift-ci-robot
Copy link
Collaborator

@jaideepr97: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/unit a9afed1 link /test unit
ci/prow/v4.5-integration-e2e a9afed1 link /test v4.5-integration-e2e

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@kadel
Copy link
Member

kadel commented Aug 13, 2020

/status blocked
let's get #3478 merged first

Also, we need to have devfile at least first draft of 2.1.0 spec first

@jaideepr97
Copy link
Author

jaideepr97 commented Aug 13, 2020

@kadel Makes sense
Are these prerequisites for the PR to be reviewed or merged?

@kadel
Copy link
Member

kadel commented Aug 13, 2020

@kadel Makes sense
Are these prerequisites for the PR to be reviewed or merged?

Just for merging.
It would be great if someone from @wtam2018 @reginapizza @ranakan19 @Shraddhak22 reviews it.

@girishramnani girishramnani added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 20, 2020
DoesComponentExist(cmpName string) (bool, error)
Deploy(parameters DeployParameters) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest call it CreateDeployment and DeleteDeployment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @girishramnani
This may be better suited for #3478 as it was introduced there and just carried over into this PR

}

// Build creates Kubernetes resources to build an image for the component
func (k Adapter) DeployDelete(manifest []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of passing the whole manifest could we consider the minimum information that is necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @girishramnani
This may be better suited for #3478 as it was introduced there and just carried over into this PR

"component": a.ComponentName,
}

if err := a.createKanikoBuilderPod(labels, initContainer(initContainerName), builderContainer(containerName, parameters.Tag, isImageRegistryInternal), regcredName); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we make this into multiple lines

return errors.Wrap(err, "error while creating kaniko builder pod")
}

podSelector := fmt.Sprintf("component=%s", a.ComponentName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have different kind of selectors present in our component/labels package and similarly in application/labels. please consider using those

return errors.Wrapf(err, "error while waiting for pod %s", podSelector)
}

defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets extract this out into a function

@@ -85,6 +85,63 @@ func (c *Client) WaitAndGetPod(watchOptions metav1.ListOptions, desiredPhase cor
}
}

// WaitAndGetPodOnInitContainerStarted blocks and waits until the named initiContainer is started.
func (c *Client) WaitAndGetPodOnInitContainerStarted(watchOptions metav1.ListOptions, initContainerName, waitMessage string, hideSpinner bool) (*corev1.Pod, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function could be reduced by using the code from other functions in this package

// Create a function to wait for deploment completion of any unstructured object
func (c *Client) waitForManifestDeployCompletion(applicationName string, gvr schema.GroupVersionResource, conditionTypeValue string) (*unstructured.Unstructured, error) {
klog.V(4).Infof("Waiting for %s manifest deployment completion", applicationName)
w, err := c.dynamicClient.Resource(gvr).Namespace(c.Namespace).Watch(metav1.ListOptions{FieldSelector: "metadata.name=" + applicationName})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I understood - this function is only being used to check if knative route is created or not. Can we actually use knative's generated library here. the dynamic client's purpose was to be used at places where the resource is provided by the user and hence cannot be associated to strongly typed resource.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @girishramnani
This may be better suited for #3478 as it was introduced there and just carried over into this PR

@girishramnani
Copy link
Contributor

did a partial pass through of the code, will take a look again soon.

@jaideepr97
Copy link
Author

did a partial pass through of the code, will take a look again soon.

Thanks for the feedback @girishramnani
Will rebase and work on the changes requested for the code introduced in this PR for now

@girishramnani
Copy link
Contributor

Closing this PR as it has diverged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Kubernetes build and deploy support in odo
9 participants