You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To contribute, add the upstream repository as an additional remote and work on a branch other than main. This approach allows you to merge changes into the main branch (reflected in GitOps workflows) and makes upstream contributions easier. Contributions from your forked main branch typically include:
16
+
17
+
. Customizations to `values-global.yaml` and other installation-specific files.
18
+
. Commits made by Tekton and other automated processes unique to your setup.
19
+
20
+
To isolate changes for upstream contributions (`hcp` is "Validated Patterns"), you can use a separate remote and branch name:
To update `hcp-main` branch with upstream changes:
32
+
33
+
[source,terminal]
34
+
----
35
+
$ git checkout hcp-main
36
+
$ git pull --rebase
37
+
----
38
+
39
+
To reflect these changes in your forked repository (useful for submitting a PR later):
40
+
41
+
[source,terminal]
42
+
----
43
+
$ git push origin hcp-main
44
+
----
45
+
46
+
To integrate upstream pattern changes into your local GitOps process:
47
+
48
+
[source,terminal]
49
+
----
50
+
$ git checkout main
51
+
$ git merge hcp-main
52
+
$ git push origin main
53
+
----
54
+
55
+
This workflow ensures that the `hcp-main` branch:
56
+
57
+
. Remains separate from changes made by your local GitOps processes.
58
+
. Can be merged or cherry-picked into your local main branch for use in GitOps workflows (useful for tracking submodule updates, such as common).
59
+
. Serves as a solid basis for Pull Requests upstream, as it will not include local configuration differences or local GitOps commits.
60
+
61
+
[id="changing-subtrees"]
62
+
== Changing subtrees
63
+
64
+
Our patterns use the Git subtree feature to promote modularity, enabling multiple patterns to share the same common base. Over time, we move more functionality into the common directory to isolate pattern-specific components as standard usage practices emerge. This approach strengthens the tools in the common directory, adds features, and simplifies the development of new patterns. Typically, we maintain the common subtree during routine updates, and pulling changes from upstream includes any updates from the common directory.
65
+
66
+
You only need to modify subtrees if you want to test changes in the common area of the pattern repositories or contribute to the common repository alongside one of the patterns. Using the pattern alone does not require changing subtrees.
67
+
68
+
For most cases involving the use and consumption of the pattern, users do not need to know that the pattern uses a subtree.
Make changes in your fork’s main branch or create a new branch for your modifications.
84
+
85
+
To track these changes in your fork of the pattern repository (e.g., `industrial-edge`), replace the common subtree with your forked version. To simplify this process use:
This script sets up a new remote in your local working directory with the specified repository. It replaces the common directory with the specified fork and branch, commits the change, but does not push it.
This replaces the common directory in the current repository with the wip-main branch from mhjacks's common repository and names the remote `common-subtree`.
102
+
103
+
To pull changes from mhjacks's wip-main branch into the parent repository:
104
+
105
+
[source,terminal]
106
+
----
107
+
$ git subtree pull --prefix common common-subtree wip-main
108
+
----
109
+
110
+
Running the script without arguments defaults to:
111
+
112
+
[source,terminal]
113
+
----
114
+
$ common/scripts/make_common_subtree.sh https://github.com/validatedpatterns/common.git main common-subtree
115
+
----
116
+
117
+
These are the default settings for the repository configuration.
118
+
119
+
[id="subtree-vs-submodule"]
120
+
== Subtree vs. Submodule
121
+
122
+
Ensuring patterns can be easily shared across multiple projects has always been a priority. While it is technically possible to share changes between unrelated Git repositories, this is a largely manual process prone to errors. We aim to offer a seamless "pull" experience, allowing a single `git pull` action to update shared pattern components. For repository sharing, we considered two main strategies: submodules and subtrees. Initially, we used submodules but later moved to subtrees.
123
+
124
+
Subtrees integrate the history of another repository into a parent repository, offering many benefits of submodules without most of their drawbacks. Atlassian provides useful documentation on subtrees, which explains their advantages in more detail. For more information see, link:https://www.atlassian.com/blog/developer[Developer's blog] and link:https://www.atlassian.com/git/tutorials/git-subtree[Git subtree].
125
+
126
+
Submodules presented unavoidable challenges, such as:
127
+
128
+
* Remembering to check out repositories with `--recurse-submodules` or running `git submodule init && git submodule sync`. The common directory often appeared empty without these steps.
129
+
* Ensuring compatibility between submodule-based repositories and other tools. While tools like ArgoCD and Tekton Pipelines supported submodules well, compatibility concerns remained.
130
+
* Switching branches where different revisions of submodules were referenced often resulted in out-of-sync states. This behavior, although is correct, could be confusing.
131
+
* Submodules required mirroring more repositories in disconnected environments.
132
+
* Working with forked submodules meant maintaining two separate repositories and multiple branches in each.
133
+
134
+
Subtrees also have challenges. For example, it is easier to diverge from the upstream version of the subtree, and users may not realize that a subtree is in use when cloning a repository. This can be considered a feature, but may lead to conflicts when updating to a newer version. Additionally, subtrees are less commonly understood, which can result in unexpected issues, such as:
135
+
136
+
137
+
* Cherry picking from a subtree commit into the parent puts the change in the parent location, not the subtree.
After forking the common repository and modifying your subtree for testing, you can propose changes to [https://github.com/validatedpatterns/common.git] for integration into other patterns. Making changes to the upstream common for a specific pattern involves two steps:
143
+
144
+
. Submit a PR to update the upstream common.
145
+
. Submit a PR to update the pattern repository with the modified common.
These patterns are designed to be composed of multiple components, and for those components to be used in gitops
15
-
workflows by consumers and contributors. To use the first pattern as an example, we maintain the link:/industrial-edge[Industrial Edge] pattern, which uses a https://github.com/validatedpatterns/industrial-edge[repo] with pattern-specific logic and configuration as well as a https://github.com/validatedpatterns/common[common repo] which has elements common to multiple patterns. The common repository is included in each pattern repository as a subtree.
14
+
Patterns are designed to be composed of multiple components, that consumers and contributors can integrate into GitOps workflows. For instance, the link:/industrial-edge[Industrial Edge] pattern comprises a https://github.com/validatedpatterns/industrial-edge[repository] with pattern-specific logic and configuration, alongside a https://github.com/validatedpatterns/common[common repository] containing elements common to various patterns. This common repository is included as a subtree within each pattern repository, streamlining consistency and reusability across different patterns.
15
+
16
16
17
17
[id="consuming-a-pattern"]
18
18
== Consuming a pattern
19
19
20
-
. Fork the pattern repository on GitHub to your workspace (GitHub user or organization). It is necessary to fork because your fork will be updated as part of the GitOps and DevOps processes, and the main branch (by default) will be used in the automated workflows.
21
-
. Clone the forked copy
20
+
. Fork the pattern repository on GitHub to your workspace (GitHub user or organization). Forking is necessary because your fork updates as part of the GitOps and DevOps processes, and the main branch (by default) is used in the automated workflows.
To update branch `hcp-main` with upstream changes:
68
-
69
-
[source,terminal]
70
-
----
71
-
$ git checkout hcp-main
72
-
$ git pull --rebase
73
-
----
74
-
75
-
To reflect these changes in your forked repository (such as if you would like to submit a PR later):
76
-
77
-
[source,terminal]
78
-
----
79
-
$ git push origin hcp-main
80
-
----
81
-
82
-
If you want to integrate upstream pattern changes into your local GitOps process:
83
-
84
-
[source,terminal]
85
-
----
86
-
$ git checkout main
87
-
$ git merge hcp-main
88
-
$ git push origin main
89
-
----
90
-
91
-
Using this workflow, the `hcp-main` branch will:
92
-
93
-
. Be isolated from any changes that are being made by your local GitOps processes
94
-
. Be merge-able (or cherry-pick-able) into your local main branch to be used by your local GitOps processes
95
-
(this is especially useful for tracking when any submodules, like common, update)
96
-
. Be a good basis for submitting Pull Requests to be integrated upstream, since it will not contain your local configuration differences or your local GitOps commits
97
-
98
-
[id="changing-subtrees"]
99
-
== Changing subtrees
100
-
101
-
Our patterns use the git subtree feature as a mechanism to promote modularity, so that multiple patterns can use the
102
-
same common basis. Over time we will move more functionality into common, to isolate the components that are
103
-
particular to each pattern, and standard usage conventions emerge. This will make the tools in common more powerful and featureful, and make it easier to develop new patterns. Normally, we will maintain the common subtree in the normal course of updates, and pulling changes from upstream will include any changes from common.
104
-
105
-
You only need to change subtrees if you want to test changes in the common/ area of the pattern repositories, or if you wish to contribute to the common/ repository itself in conjunction with one of the patterns. Using the pattern by itself _does not_ require changing subtrees.
106
-
107
-
For the common cases (use and consumption of the pattern), users do not need to be aware that the pattern uses a subtree at all.
Now, you can make changes in your fork's main branch, or else make a new branch and make changes there.
122
-
123
-
If you want to track these changes in your fork of the _pattern_ repository (industrial-edge in this case), you will need to swap out the subtree in industrial-edge for the version of common you forked. We have provided a script to make this a bit easier:
This script will set up a new remote in your local working directory with the repository you specify. It will replace the common directory with a new common from the fork and branch you specify, and commit it. The script will _not_ push the result.
This will replace common in the current repository with the wip-main branch from the common in mhjacks's common repository, and call the remote common-subtree.
140
-
141
-
From that point, changes from mhjacks's wip-main branch on mhjacks's fork of common can be pulled in this way:
142
-
143
-
[source,terminal]
144
-
----
145
-
$ git subtree pull --prefix common common-subtree wip-main
146
-
----
147
-
148
-
When run without arguments, the script will run as if it had been given the following arguments:
149
-
150
-
[source,terminal]
151
-
----
152
-
$ common/scripts/make_common_subtree.sh https://github.com/validatedpatterns/common.git main common-subtree
153
-
----
154
-
155
-
Which are the defaults the repository is normally configured with.
156
-
157
-
[id="subtree-vs-submodule"]
158
-
== Subtree vs. Submodule
159
-
160
-
It has always been important to us to be have a substrate for patterns that is as easy as possible to share amongst
161
-
multiple patterns. While it is possible to share changes between multiple unrelated git repositories, it is an almost
162
-
entirely manual process, prone to error. We feel it is important to be able to provide a "pull" experience (i.e. one git "pull" type action) to update the shared components of a pattern. Two strategies exist for repository sharing in this way: submodule and subtree. We started with submodules but have since moved to subtree.
163
-
164
-
Atlassian has some good documentation on what subtree is https://blog.developer.atlassian.com/the-power-of-git-subtree/[here] and https://www.atlassian.com/git/tutorials/git-subtree[here]. In short, a subtree integrates another repository's history into a parent repository, which allows for most of the benefits of a submodule workflow, without most of the caveats.
165
-
166
-
Earlier versions of this document described the usage of patterns with submodules instead of subtrees. In the earliest stages of pattern development, we used submodules because the developers of the project were familiar with submodules and had used them previously, but we had not used subtrees. User feedback, as well as some of the unavoidable complexities of submodules, convinced us to try subtrees and we believe we will stick with that strategy. Some of the unavoidable complexities of submodules include:
167
-
168
-
* Having to remember to checkout repositories with `--recurse-submdules`, or else doing `git submodule init && git submodule sync`. Experienced developers asked in several of our support channels early on why common was empty.
169
-
* Hoping that other tools that are interacting with the repository are compatible with the submodule approach. (To be fair, tools like ArgoCD and Tekton Pipelines did this very well; their support of submodules was one of the key reasons we started with submodules)
170
-
* When changing branches on a submoduled repository, if the branch you were changing to was pointed to a different revision of the submoduled repository, the repository would show out of sync. While this behavior is correct, it can be surprising and difficult to navigate.
171
-
* In disconnected environments, submodules require mirroring more repositories.
172
-
* Developing with a fork of the submoduled repository means maintaining two forked repositories and multiple branches in both.
173
-
174
-
Subtrees have some pitfalls as well. In the subtree strategy, it is easier to diverge from the upstream version of the subtree repository, and in fact with a typical `git clone`, the user may not be aware that a subtree is in use at all. This can be considered a feature, but could become problematic if the user/consumer later wants to update to a newer version of the subtree but local changes might conflict. Additionally, since subtrees are not as well understood generally, there can be some surprising effects. In practice, we have run into the following:
175
-
176
-
* Cherry picking from a subtree commit into the parent puts the change in the parent location, not the subtree
Once you have forked common and changed your subtree for testing, changes from your fork can then be proposed to [https://github.com/validatedpatterns/common.git] and can then be integrated into other patterns. A change to upstream common for a particular upstream pattern would have to be done in two stages:
182
-
183
-
. PR the change into upstream's common
184
-
. PR the updated common into the pattern repository
0 commit comments