-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix issue #26: Cleanup and simplify code logic #28
Conversation
@SamYuan1990 , Please help review, thanks. |
I am not sure. @marceloamaral , if we are considering with local dev env step up usage.... we may have to block this PR or at least a change request here. |
Agree, prerequisite well-known or popular packages should be maintained by machine owner, only those project specific tools need be taken care of by project's GHA code, IMO. |
I suppose we need a discussion as do we need handle kubectl and kind install script or not. I am now open for it. As one of the question covered in this PR. |
common.sh
Outdated
@@ -20,9 +20,6 @@ | |||
set -ex | |||
set -o pipefail | |||
|
|||
_registry_port="5001" |
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.
en.... I don't like force port number. I hope to keep it flexible.
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.
The reason why I chose to fix the port here is that if remain such flexibility, then we have a very ugly sed scripts to replace the port info inside the local-registry.yml.
As you could see in current PR diff, I also cleaned up there to make code cleaner:)
Flexibility often comes with complexity:) So we may do trade-off.
Some of the options are not so important to users, such as the registry port, for local-dev use and CI use, IMO, fix to 5001 is acceptable.
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.
if we have to flexible with port number, any better solution than sed?
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.
Maybe we can use ex command like this:
ex -s -c "1,\$s/$kind_registry_name/${KIND_REGISTRY_NAME}/ge" -c "x" "${KIND_DIR}"/kind.yml
I think it is available on Mac and Linux
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.
Maybe we can use ex command like this:
ex -s -c "1,\$s/$kind_registry_name/${KIND_REGISTRY_NAME}/ge" -c "x" "${KIND_DIR}"/kind.yml
I think it is available on Mac and Linux
In my dev machine, the ex
points to the same binary as vim
:-)
$ ls -l /usr/bin/ex
lrwxrwxrwx 1 root root 20 Aug 24 2021 /usr/bin/ex -> /etc/alternatives/ex
$ ls -l /usr/bin/vim
lrwxrwxrwx 1 root root 21 Aug 24 2021 /usr/bin/vim -> /etc/alternatives/vim
$ ls -l /etc/alternatives/ex
lrwxrwxrwx 1 root root 18 Aug 24 2021 /etc/alternatives/ex -> /usr/bin/vim.basic
$ ls -l /etc/alternatives/vim
lrwxrwxrwx 1 root root 18 Aug 24 2021 /etc/alternatives/vim -> /usr/bin/vim.basic
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.
Yes, it's the line editor for vim 😅
It was new to me as well
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.
em... well technologically maybe sed still one of best options?
I mean just when we replace string via shell.
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.
This issue is fixed in #31 by using sed < manifest/yaml > generated/yaml
kind/kind.sh
Outdated
echo "Building manifests..." | ||
|
||
cp $KIND_MANIFESTS_DIR/kind.yml "${KIND_DIR}"/kind.yml | ||
sed "s/$kind_registry_name/${KIND_REGISTRY_NAME}/g" "${KIND_DIR}"/kind.yml > "${KIND_DIR}"/kind.yml.tmp && mv "${KIND_DIR}"/kind.yml.tmp "${KIND_DIR}"/kind.yml |
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.
sed has different behaviors on mac and linux. :-)
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.
as I don't want to block mac user use this repo to setup their own dev cluster at local.
but... it seems the changes here is about do we need flexibility on port number?
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.
Exactly, why not we fix the content of both kind.yml and local-registry.yml :)
I agree that we need a consensus on this. Do we want to use local-dev-cluster only for CI env setup or for local env setup as well? |
My answer is both. But the point here is that prerequisite package setup should be one-shot job, it should be handled by runner admin or dev cluster owner. IMO, such kind/kubectl installation job is similar as Golang setup.
I agree that we should give convenience for developers to quickly setup local dev cluster and do quick try on Kepler. Many famous and successful open source projects have their fundamental prerequisite package lists, install them either manually or through user local scripts does not mean manual invention since this is dev env setup, not the project itself stuffs. |
Both.
@marceloamaral what do you think if we turn this repo from an empty linux to an environment same with today's GHA dependence? IMO,
With a possible case, just assume this repo running on a self hosted instance, maybe triggered by GHA or not. |
As for today, I keep my standard to review this PR as the same for https://github.com/sustainable-computing-io/local-dev-cluster/pull/9/files if it doesn't break CI, then I can accept with merge it. |
Thanks @SamYuan1990 's comments above, let me clarify two things:
|
I have refactor PR that "cleans up" the setup script - #31 |
@sthaha , I like your idea to adjust the directory hierarchy and also code location such as moving code from common.sh to main.sh. Please hold on and give me some time to refine current PR based on above comments, then you can move on accordingly, thanks. |
Just tried, |
AFAIK |
@jiere .... as mentioned in sustainable-computing-io/kepler-action#50 (comment) if we just considering with GHA, even if self host instance, then it works. but for other CI pipelines, as travis ... are those binaries are default settings? I am not sure... |
@rootfs , what do you think of , do we need considering with other CI tools and keep kubectl and kind binary install today? |
summary for today's status. Please correct me for any mistake.
|
README.md
Outdated
|
||
## Start up | ||
1. Modify kind [config](./kind/manifests/kind.yml) to make sure `extraMounts:` cover the linux header and BCC. | ||
1. Modify kind [config](./kind/kind.yml) to make sure `extraMounts:` cover the linux header and BCC. | ||
2. Export `CLUSTER_PROVIDER` env variable: | ||
``` | ||
export CLUSTER_PROVIDER=kind/microshift |
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.
We should change to the or
symbol: export CLUSTER_PROVIDER=[kind|microshift]
is better
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.
It seems that export
grammar does not support such writings, let me change as:
export CLUSTER_PROVIDER=kind or export CLUSTER_PROVIDER=microshift
, is this acceptable for you? @marceloamaral
I am open to utilizing pre-defined GHA (GitHub Actions) as long as we ensure consistency with the local cluster deployment. It is important for the developer to have a similar environment to test before pushing a commit. Ultimately, we should use what makes the most sense for us. |
hence recall myself, I prefer to merge this PR base on what we have today. |
kind/kind.sh
Outdated
function _prepare_config() { | ||
echo "Building manifests..." | ||
# replace registry name in kind.yml | ||
sed -i "s/kind-registry/${KIND_REGISTRY_NAME}/g" ${KIND_DIR}/kind.yml |
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.
@jiere sed -i
will not work on mac. The script fails with this change on mac
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.
Yes, I did see @sthaha 's suggestion above, let me change a new version and force-push diff again.
kind/kind.sh
Outdated
function _fetch_kind() { | ||
mkdir -p "${KIND_DIR}" | ||
KIND="${KIND_DIR}"/.kind | ||
if [ -f "$KIND" ]; then | ||
current_kind_version=$($KIND --version | awk '{print $3}') | ||
fi | ||
if [[ $current_kind_version != $KIND_VERSION ]]; then | ||
echo "Downloading kind v$KIND_VERSION" | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
curl -LSs https://github.com/kubernetes-sigs/kind/releases/download/v$KIND_VERSION/kind-darwin-${ARCH} -o "$KIND" | ||
else | ||
curl -LSs https://github.com/kubernetes-sigs/kind/releases/download/v$KIND_VERSION/kind-linux-${ARCH} -o "$KIND" | ||
fi | ||
chmod +x "$KIND" | ||
fi | ||
} | ||
|
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.
imho, we shouldn't remove this rather use the approach in #31 to validate if kind exists
and the version is as expected.
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.
@sthaha , the key idea for this PR is not statically or ENV-based define the kind version, we just need to transfer the kind
installation effort to runner admin, just as Github-hosted runners
do. For developers, he/she needs to do one-shot installation of kind
and kubectl
when he setup his/her test machine at the very beginning.
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.
I agree about the installation part, but the validation for the versions must be performed in the script to ensure everyone stays on the same version. We can also add --no-validate or --ci
flag to suppress unnecessary validations in CI.
kind/kind.sh
Outdated
_prepare_config | ||
_setup_kind | ||
_run_kind_registry |
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.
I think the function should adhere to single-responsiblity principle and only setup kind, not the registry. Use a different function (like it was earlier) to setup registry.
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.
Yeah, the reason why I added _run_kind_registry
into kind_up
is just to let the kind
code in current common.sh align with behavior of microshift
code.
For current diff, _setup_kind
and _run_kind_registry
are two steps for _kind_up
, each has single-responsibility already; In common.sh, both kind
and microshift
cluster setup will have two similar steps: _xxx_up
and _wait_for_clusterReady
, not like current 3 steps for kind
and 2 steps for microshift
:-)
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.
Speaking of which could this change please wait for #31 which does a major overhaul of the scripts merge?
verify.sh
Outdated
kubectl cluster-info | ||
if [ "$?" != 0 ]; then |
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.
Consider these 2 alternatives
- My preference - use
&& ||
kubectl cluster-info || { echo "failed .. "; return 1; }
in #31 I have a generic die
method that exits 1
- No need to use
if [
if ! kubectl cluster-info ; then
...
fi
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.
Cool, I like the first one :-) Thanks.
The initial reason for me to change here is just removing the original console warning.
Checked your diff in #31, since current diff is just subset of yours, let me back out my change here and leave it to yours :-)
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.
kind/kind.sh
Outdated
if [ -f "$KIND" ]; then | ||
current_kind_version=$($KIND --version | awk '{print $3}') | ||
fi | ||
if [[ $current_kind_version != $KIND_VERSION ]]; then |
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.
can we move this validation to verify.sh tools
instead? This allows everyone to validate if the versions of the binaries in path are good!
CI failed
|
Missed one line deletion... My bad, let me rebase again... |
1. For `kubectl` and `kind`, using Github-hosted runners' provisioned version. 2. Simplify code logic, remove some unnecessary ENV options. Signed-off-by: Jie Ren <[email protected]>
See #26
Major change:
kubectl
andkind
, using Github-hosted runners' provisioned version.After this PR be merged, will cleanup related code in kepler-action repo accordingly.
Signed-off-by: Jie Ren [email protected]