-
Notifications
You must be signed in to change notification settings - Fork 243
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
Support autoBuild
and deployByDefault
on Image and Kubernetes/OpenShift components
#6654
Merged
openshift-merge-robot
merged 23 commits into
redhat-developer:main
from
rm3l:5694-implement-autobuild-and-deploybydefault
Apr 5, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
dddb2dc
Add sample Devfile with multiple autoBuild/deployByDefault combinations
rm3l d3a9420
Add helper function to update a given Devfile Command Group
rm3l 35a6e50
Add test cases for 'odo dev'
rm3l 125ff54
Add test cases for 'odo deploy'
rm3l 510c5db
Add test cases for 'odo build-images'
rm3l 344879a
Display the spinner when creating or updating Kubernetes resources
rm3l cbbd52a
Handle deployByDefault on K8s and OpenShift components
rm3l 399b42c
Add 'devfile.GetImageComponentsToPush' functions that returns the lis…
rm3l 669b6a8
Handle automatic image component creation for 'odo dev' on Kubernetes
rm3l b14213a
Handle automatic image component creation for 'odo dev' on Podman
rm3l 3058f5a
Handle automatic image and K8s/OpenShift component creation for 'odo …
rm3l 035e826
Bump Devfile library to the latest commit at this time (c1b23d2)
rm3l 0760872
Do not set default values when parsing a Devfile
rm3l 228c704
Add documentation in the Devfile reference page
rm3l 5ef6655
Revert "Display the spinner when creating or updating Kubernetes reso…
rm3l d027561
Avoid re-applying Image components multiple times
rm3l 2ad44e8
Move GetK8sAndOcComponentsToPush and GetImageComponentsToPush to libd…
rm3l bba3c88
fixup! Handle automatic image and K8s/OpenShift component creation fo…
rm3l f6887b5
fixup! Handle automatic image component creation for 'odo dev' on Podman
rm3l 71e0ba2
fixup! Avoid re-applying Image components multiple times
rm3l 7a1f1a0
Apply suggestions from code review
rm3l 3673d01
fixup! Do not set default values when parsing a Devfile
rm3l dc0fe61
Fix devfile-deploy-functional-pods.yaml (used in 'odo logs' tests)
rm3l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,7 +19,9 @@ For this reference, we use one singular (working) Node.js example which can be r | |||||||||||||||||
|
||||||||||||||||||
When `odo dev` is ran, `odo` creates the following Kubernetes resources from `container` (component) and `exec` (command) sections of the Devfile: | ||||||||||||||||||
* Deployment for running the containers | ||||||||||||||||||
* Service for accessibility | ||||||||||||||||||
* Service for accessibility | ||||||||||||||||||
|
||||||||||||||||||
See [How odo dev translates a container component into Kubernetes resources](./architecture/how-odo-works.md#how-odo-dev-translates-a-container-component-into-kubernetes-resources) for more details. | ||||||||||||||||||
|
||||||||||||||||||
### File Synchronization | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -90,7 +92,7 @@ The most common deploy scenario is the following: | |||||||||||||||||
1. Use the `image` component to build a container | ||||||||||||||||||
2. Deploy a `kubernetes` component(s) with a Kubernetes resource defined | ||||||||||||||||||
|
||||||||||||||||||
### How odo runs exec commands in Deploy mode | ||||||||||||||||||
### How `odo` runs exec commands in Deploy mode | ||||||||||||||||||
```yaml | ||||||||||||||||||
commands: | ||||||||||||||||||
- id: deploy-db | ||||||||||||||||||
|
@@ -140,6 +142,157 @@ Commands defined by the `exec` command are run inside a container started by a [ | |||||||||||||||||
4. The Kubernetes Job is created with appropriate annotations and labels so that it can be deleted by `odo delete component --name <name>` command if the need be. | ||||||||||||||||||
5. If the Kubernetes Job fails, a new pod is created to re-run the job instead of re-running it inside the same pod's container, this ensures that we can fetch the logs when needed. | ||||||||||||||||||
|
||||||||||||||||||
### How `odo` determines components that are applied automatically | ||||||||||||||||||
|
||||||||||||||||||
When running `odo dev` or `odo deploy`, `odo` determines components that need to be applied automatically by looking at several things: | ||||||||||||||||||
- whether the component is referenced by any [`apply` commands](https://devfile.io/docs/2.2.0/adding-an-apply-command); | ||||||||||||||||||
- and looking at dedicated fields that allow to explicitly control this behavior: | ||||||||||||||||||
- `autoBuild` on [Image components](https://devfile.io/docs/2.2.0/adding-an-image-component) | ||||||||||||||||||
- `deployByDefault` on [Kubernetes or OpenShift components](https://devfile.io/docs/2.2.0/adding-a-kubernetes-or-openshift-component) | ||||||||||||||||||
|
||||||||||||||||||
#### `autoBuild` for Image Components | ||||||||||||||||||
|
||||||||||||||||||
An Image component is applied automatically if **any** of the following conditions are met: | ||||||||||||||||||
- `autoBuild` is `true` | ||||||||||||||||||
- `autoBuild` is not set, **and** this Image component is not referenced in any `apply` commands | ||||||||||||||||||
|
||||||||||||||||||
If the Image component is referenced by an `apply` command, it will be applied when this command is invoked. | ||||||||||||||||||
|
||||||||||||||||||
For example, given the following excerpt: | ||||||||||||||||||
```yaml | ||||||||||||||||||
variables: | ||||||||||||||||||
CONTAINER_IMAGE_REPO: localhost:5000/odo-dev/node | ||||||||||||||||||
|
||||||||||||||||||
components: | ||||||||||||||||||
# autoBuild true => automatically created on startup | ||||||||||||||||||
- image: | ||||||||||||||||||
autoBuild: true | ||||||||||||||||||
dockerfile: | ||||||||||||||||||
buildContext: . | ||||||||||||||||||
uri: Dockerfile | ||||||||||||||||||
imageName: "{{ CONTAINER_IMAGE_REPO }}:autobuild-true" | ||||||||||||||||||
name: "autobuild-true" | ||||||||||||||||||
|
||||||||||||||||||
# autoBuild false, referenced in apply command => created when apply command is invoked | ||||||||||||||||||
- image: | ||||||||||||||||||
autoBuild: false | ||||||||||||||||||
dockerfile: | ||||||||||||||||||
buildContext: . | ||||||||||||||||||
uri: Dockerfile | ||||||||||||||||||
imageName: "{{ CONTAINER_IMAGE_REPO }}:autobuild-false-and-referenced" | ||||||||||||||||||
name: "autobuild-false-and-referenced" | ||||||||||||||||||
|
||||||||||||||||||
# autoBuild not set, not referenced in apply command => automatically created on startup | ||||||||||||||||||
- image: | ||||||||||||||||||
dockerfile: | ||||||||||||||||||
buildContext: . | ||||||||||||||||||
uri: Dockerfile | ||||||||||||||||||
imageName: "{{ CONTAINER_IMAGE_REPO }}:autobuild-not-set-and-not-referenced" | ||||||||||||||||||
name: "autobuild-not-set-and-not-referenced" | ||||||||||||||||||
|
||||||||||||||||||
- container: | ||||||||||||||||||
image: "{{ CONTAINER_IMAGE_REPO }}:autobuild-not-set-and-not-referenced" | ||||||||||||||||||
name: runtime | ||||||||||||||||||
commands: | ||||||||||||||||||
- apply: | ||||||||||||||||||
component: autobuild-false-and-referenced | ||||||||||||||||||
id: image-autobuild-false-and-referenced | ||||||||||||||||||
|
||||||||||||||||||
- composite: | ||||||||||||||||||
commands: | ||||||||||||||||||
- image-autobuild-false-and-referenced | ||||||||||||||||||
- start-app | ||||||||||||||||||
group: | ||||||||||||||||||
isDefault: true | ||||||||||||||||||
kind: run | ||||||||||||||||||
id: run | ||||||||||||||||||
|
||||||||||||||||||
- composite: | ||||||||||||||||||
commands: | ||||||||||||||||||
- image-autobuild-false-and-referenced | ||||||||||||||||||
- deploy-k8s | ||||||||||||||||||
group: | ||||||||||||||||||
isDefault: true | ||||||||||||||||||
kind: deploy | ||||||||||||||||||
id: deploy | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
When running `odo`, the following Image components will be applied automatically, before applying any other components and invoking any commands: | ||||||||||||||||||
- `autobuild-true` because it has `autoBuild` set to `true`. | ||||||||||||||||||
- `autobuild-not-set-and-not-referenced` because it doesn't set `autoBuild` and is not referenced by any `apply` commands. | ||||||||||||||||||
|
||||||||||||||||||
Because the `image` component `autobuild-false-and-referenced` is referenced by the `apply` command `image-autobuild-false-and-referenced`, it will be applied when this command | ||||||||||||||||||
is invoked, that is, in this example, when the `run` or `deploy` commands are invoked. | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
#### `deployByDefault` for Kubernetes/OpenShift Components | ||||||||||||||||||
|
||||||||||||||||||
A Kubernetes or OpenShift component is applied automatically if **any** of the following conditions are met: | ||||||||||||||||||
- `deployByDefault` is `true` | ||||||||||||||||||
- `deployByDefault` is not set, **and** this component is not referenced in any `apply` commands | ||||||||||||||||||
|
||||||||||||||||||
If the component is referenced by an `apply` command, it will be applied when this command is invoked. | ||||||||||||||||||
|
||||||||||||||||||
For example, given the following excerpt (simplified to use only Kubernetes components, but the same behavior applies to OpenShift ones): | ||||||||||||||||||
```yaml | ||||||||||||||||||
variables: | ||||||||||||||||||
CONTAINER_IMAGE_REPO: localhost:5000/odo-dev/node | ||||||||||||||||||
|
||||||||||||||||||
components: | ||||||||||||||||||
# deployByDefault true => automatically created on startup | ||||||||||||||||||
- kubernetes: | ||||||||||||||||||
deployByDefault: true | ||||||||||||||||||
inlined: | | ||||||||||||||||||
[...] | ||||||||||||||||||
name: "k8s-deploybydefault-true" | ||||||||||||||||||
|
||||||||||||||||||
# deployByDefault false, referenced in apply command => created when apply command is invoked | ||||||||||||||||||
- kubernetes: | ||||||||||||||||||
deployByDefault: false | ||||||||||||||||||
inlined: | | ||||||||||||||||||
[...] | ||||||||||||||||||
name: "k8s-deploybydefault-false-and-referenced" | ||||||||||||||||||
|
||||||||||||||||||
# deployByDefault not set, not referenced in apply command => automatically created on startup | ||||||||||||||||||
- kubernetes: | ||||||||||||||||||
inlined: | | ||||||||||||||||||
[...] | ||||||||||||||||||
name: "k8s-deploybydefault-not-set-and-not-referenced" | ||||||||||||||||||
|
||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if you can add an example where deployByDefault is false, and not referenced in apply command.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in |
||||||||||||||||||
- container: | ||||||||||||||||||
image: "{{ CONTAINER_IMAGE_REPO }}:autobuild-not-set-and-not-referenced" | ||||||||||||||||||
name: runtime | ||||||||||||||||||
commands: | ||||||||||||||||||
- apply: | ||||||||||||||||||
component: k8s-deploybydefault-false-and-referenced | ||||||||||||||||||
id: apply-k8s-deploybydefault-false-and-referenced | ||||||||||||||||||
|
||||||||||||||||||
- composite: | ||||||||||||||||||
commands: | ||||||||||||||||||
- apply-k8s-deploybydefault-false-and-referenced | ||||||||||||||||||
- start-app | ||||||||||||||||||
group: | ||||||||||||||||||
isDefault: true | ||||||||||||||||||
kind: run | ||||||||||||||||||
id: run | ||||||||||||||||||
|
||||||||||||||||||
- composite: | ||||||||||||||||||
commands: | ||||||||||||||||||
- apply-k8s-deploybydefault-false-and-referenced | ||||||||||||||||||
- deploy-k8s | ||||||||||||||||||
group: | ||||||||||||||||||
isDefault: true | ||||||||||||||||||
kind: deploy | ||||||||||||||||||
id: deploy | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
When running `odo`, the following Kubernetes components will be applied automatically, before applying any other components and invoking any commands: | ||||||||||||||||||
- `k8s-deploybydefault-true` because it has `deployByDefault` set to `true`. | ||||||||||||||||||
- `k8s-deploybydefault-not-set-and-not-referenced` because it doesn't set `deployByDefault` and is not referenced by any `apply` commands. | ||||||||||||||||||
|
||||||||||||||||||
Because the `kubernetes` component `k8s-deploybydefault-false-and-referenced` is referenced by the `apply` command `apply-k8s-deploybydefault-false-and-referenced` , it will be applied when this command | ||||||||||||||||||
is invoked, that is, in this example, when the `run` or `deploy` commands are invoked. | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
## File Reference | ||||||||||||||||||
|
||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be helpful to add one more component with
autoBuild:false
and not referenced?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in
9060596
(#6720)