Defining component relationships
When a workspace includes multiple components, their repositories might contain references to image builds of another component. For instance, an application might include multiple child components that, using a Dockerfile FROM
clause, reference the image build of a common parent. Or, a component might reference image builds from another application altogether. OpenShift operators, for example, often have references to several components across applications.
In such instances, whenever you build a new image of the common parent component, you need to update the references to it. Specifically, you need to copy and paste the pullspec and image digest of that new image to your other source repositories. This process is tedious and error-prone.
However, if you build an application with Konflux and make references between components with image digests (sha256:…
), Konflux can automatically generate pull requests to update those references. To use this functionality, simply define the relationships between your components, either in the Konflux UI, or in your CLI.
By default, Konflux only looks for image digest references in Dockerfiles, Containerfiles, and YAML files. However, you can customize your build pipeline to adjust that list of files with an annotation. This functionality is only available for push builds, so add the following annotation under The existing list of patterns is: ".*Dockerfile.*, .*.yaml, .*Containerfile.*" |
In the UI
To define the relationships between components in a workspace, complete the following steps in the Konflux UI:
Currently, applications with only one component do not have the option to define relationships in the UI. To achieve the same result for single-component applications, you can define the relationship in the CLI. |
-
Navigate to your application.
-
On any tab, use the Actions drop-down menu to select Define component relationships.
-
Alternatively, go to the Components tab and select the Define component relationships.
-
-
In the Component relationships window, select one component from the Select a component drop-down menu.
-
Select Nudges or Is nudged by, depending on the relationship you wish to define.
Component A nudges Component B (or Component B is nudged by Component A) if Component B contains a reference, by image digest, to a build of Component A. After successful push builds of Component A, nudging updates the image digest that Component B references.
-
Use the remaining drop-down menu to choose which other components belong to this relationship.
-
To define multiple relationships, select Add another component relationship.
-
Once you have defined all necessary relationships, select Save relationships.
To verify the new relationship in the UI: . Go to the Components tab for your application. . Select a component that belongs to the relationship you defined. . Scroll to the end of the page and select Show related components.
Alternatively, in the git repo for the component that nudges, push a commit. When the build for that component completes, you should see a new pull request appear for the component that is nudged. This new pull request contains the image digest for the new build of its parent image.
-
On any tab, use the Actions drop-down menu to select Define component relationships. If you do not see the relationship, try to define it again and then make sure to select Save relationships.
-
Ensure that the existing references in the repositories of your components are correct.
In the CLI
Prerequisites:
-
You have completed the steps listed in the Getting started in the CLI page.
-
In your CLI, login to Konflux.
-
List your components, and identify the names of the components you want to relate to each other.
kubectl get components
Component A nudges Component B (or Component B is nudged by Component A) if Component B contains a reference by image digest to a build of Component A. After successful push builds of Component A, nudging updates the image digest that Component B references.
-
Patch the components to establish the nudging relationship.
kubectl patch components/<name of component that nudges> -p '{"spec":{"build-nudges-ref": ["<name of component that is nudged>"]}}' --type=merge --kubeconfig=<path to kubeconfig>
You can also use kubectl edit to add the build-nudges-ref instead of patching the component. -
You found the names of the two components in the last step.
-
The
kubeconfig
and its path are the same you used to login to Konflux.
-
-
Get the component custom resource (CR) definition for the components that nudges. The definition should include a line that says
build-nudges-ref:
, and beneath that, the name of the component that is nudged.kubectl get components/<name of component that nudges> -o yaml --kubeconfig=<path to kubeconfig> | less
-
Push a commit to the component that nudges. When the build completes, you should see a new pull request appear for the component that is nudged. This new pull request contains the image digest for the new build of the parent image.
-
Ensure that the existing references in the repositories of your components are correct.
-
Try running the necessary commands again, and ensure you have the correct syntax.