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

enable stsstack to also support non-openstack clouds #227 #228

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

zhhuabj
Copy link
Contributor

@zhhuabj zhhuabj commented Sep 6, 2024

In fact, stsstack can work well on lxd cloud as well. So this patch is to enable stsstack to not only support underlying openstack cloud, but also support underlying lxd and maas cloud.

vip_start=${MASTER_OPTS[VIP_ADDR_START]}
cidr=""
if [[ -z $vip_start ]] && [[ -e ~/novarc ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

Think you can simply change this by changing:

if [[ -z $vip_start ]] && [[ -e ~/novarc ]]; then

to:

if [[ -z $vip_start ]] && [[ -e ~/novarc ]] && [[ $type = openstack ]]; then

Then you wouldn't check twice inside the if. And can also drop the cidr="" too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi pon, I made the modifications as you suggested,

if [[ -z $vip_start ]] && [[ -e ~/novarc ]] && [[ $type = openstack ]]; then

and also added the following code to improve it. thanks.

elif [[ -z $vip_start ]]; then
echo "ERROR: No VIP start address provided with --vip-addr-start for the $type cloud."
exit 1

common/helpers Outdated
@@ -43,6 +43,13 @@ list_overlays ()
} | sort -u
}

get_cloud_type ()
{
local cloud=`juju show-model| sed -rn 's/.+cloud:\s*(.+).*/\1/p'| uniq`
Copy link
Member

@pponnuvel pponnuvel Sep 6, 2024

Choose a reason for hiding this comment

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

jq is better than parsing yaml with sed (it can also get unique values):

   local cloud=$(juju show-model --format json |jq -r '[.[].cloud] | unique[]')
   local type=$(juju show-cloud $cloud --format json | jq -r '[.[].type] | unique[]')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi pon, yes, jq is better than parsing yaml with sed. Although I merely relocated two original lines without modifying the previous code (perhaps the optimized code should submit another pr), I have now modified to using jq instead of sed to align with your suggestion. thanks for the review.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks Joshua. Looks good now!

if [[ $type = openstack ]]; then
# stsstack
cidr=$(source ~/novarc; openstack subnet show ${OS_USERNAME}_admin_subnet -c cidr -f value 2>/dev/null)
fi
if [[ -n $cidr ]]; then
vip_start=$(echo $cidr| sed -r 's/([0-9]+\.[0-9]+).+/\1/g').150.0
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think all the above code should be under the 'openstack' if since it is only used in that case, correct? Then you wouldn't need the cidr="" assignment either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi brian, I have added the following code for non-openstack cloud to improve this scene. thanks for the review.

elif [[ -z $vip_start ]]; then
echo "ERROR: No VIP start address provided with --vip-addr-start for the $type cloud."
exit 1

Copy link
Member

@pponnuvel pponnuvel left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -26,6 +27,9 @@ if [[ -z $vip_start ]] && [[ -e ~/novarc ]]; then
net_end=$(awk -F'.' '/HostMax/{print $NF}' <<<$(ipcalc -b $cidr))
vip_start=$(echo $cidr| sed -r 's/([0-9]+\.[0-9]+\.[0-9]+).+/\1/g').$((net_end - 19))
fi
elif [[ -z $vip_start ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

i think this is going to fail if using maas without vips which i presume is not the intention?

e.g. i did the following:

$ ./generate-bundle.sh --hyperconverged
parse error: Invalid numeric literal at line 1, column 11
parse error: Invalid numeric literal at line 1, column 11
parse error: Invalid numeric literal at line 1, column 11
parse error: Invalid numeric literal at line 1, column 11
ERROR: No VIP start address provided with --vip-addr-start for the  cloud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ed, I remove that line now, thanks.
$ ./generate-bundle.sh --hyperconverged
ERROR: no default binding provided. Use --default-binding

In fact, stsstack can also work well on lxd
cloud. So this patch is to enable stsstack to not
only support underlying openstack cloud, but also
support underlying lxd and maas cloud.
@dosaboy dosaboy merged commit 83b6f9b into canonical:main Sep 11, 2024
3 checks passed
zhhuabj added a commit to zhhuabj/stsstack-bundles that referenced this pull request Sep 19, 2024
The PR canonical#228 [1] changed to use jq instead of sed to parse yaml
when relocating two lines. However, yaml format is not supported
in versions prior to juju 3.x.

$ juju show-cloud lxd --format json
ERROR invalid value "json" for option --format: unknown format "json"

Therefore, we need to revert back to the previous two lines
to support both juju 2.x and juju 3.x simultaneously.

[1] canonical#228
zhhuabj added a commit to zhhuabj/stsstack-bundles that referenced this pull request Sep 19, 2024
The PR canonical#228 [1] changed to use jq instead of sed to parse yaml
when relocating two lines. However, yaml format is not supported
in versions prior to juju 3.x.

$ juju show-cloud localhost --format json
ERROR invalid value "json" for option --format: unknown format "json"

Therefore, we need to revert back to the previous two lines
to support both juju 2.x and juju 3.x simultaneously.

[1] canonical#228
slapcat pushed a commit to slapcat/stsstack-bundles that referenced this pull request Nov 7, 2024
The PR canonical#228 [1] changed to use jq instead of sed to parse yaml
when relocating two lines. However, yaml format is not supported
in versions prior to juju 3.x.

$ juju show-cloud localhost --format json
ERROR invalid value "json" for option --format: unknown format "json"

Therefore, we need to revert back to the previous two lines
to support both juju 2.x and juju 3.x simultaneously.

[1] canonical#228
slapcat pushed a commit to slapcat/stsstack-bundles that referenced this pull request Nov 10, 2024
The PR canonical#228 [1] changed to use jq instead of sed to parse yaml
when relocating two lines. However, yaml format is not supported
in versions prior to juju 3.x.

$ juju show-cloud localhost --format json
ERROR invalid value "json" for option --format: unknown format "json"

Therefore, we need to revert back to the previous two lines
to support both juju 2.x and juju 3.x simultaneously.

[1] canonical#228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants