-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Merge inventory-generator with origin-ansible image #5043
Merge inventory-generator with origin-ansible image #5043
Conversation
c3c7e45
to
cae4164
Compare
@juanvallejo you have some YAML-lint errors: https://travis-ci.org/openshift/openshift-ansible/jobs/262695660#L669 |
|
||
RUN INSTALL_PKGS="openssh-clients wget git" \ | ||
&& yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS \ | ||
&& EPEL_PKGS="PyYAML ansible python2-boto" \ |
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.
Why don't we enable EPEL first and then install all packages at once?
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.
EPEL packages sometimes shadow official packages, which we would usually prefer. There are two basic ways to prevent this - this is one - the other is to define the EPEL repo but leave it inactive and only enable it for the yum transactions needed. Either way you end up separating out the EPEL dependencies.
The other reason to do this is because it identifies which packages are "gaps" in the official packages. In the downstream these tend to require some different treatment, either shipping packages in another channel, getting them via RHSCL, or making them unnecessary somehow. And if things change and the packages are no longer needed... it becomes obvious you can get rid of EPEL.
ENV APP_ROOT=/opt/app-root \ | ||
HOME=/opt/app-root/src \ | ||
WORK_DIR=/opt/app-root \ | ||
USER_UID=1001 |
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.
Bad indentation / alignment.
chown ${USER_UID}:0 ${HOME} | ||
chmod ug+rwx -R ${HOME} | ||
|
||
# runtime user will need to be able to self-insert in /etc/passwd |
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.
Why does the user needs to edit /etc/passwd
?
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.
Ah, will word that comment a bit better. This comment justifies the need to make /etc/passwd
writable, in order to tie a username to the given uid. This is required for ssh to work from within the container
chmod g+rw /opt/app-root/src | ||
|
||
# ensure that the ansible content is accessible | ||
chmod -R g+r ${WORK_DIR} /bin |
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.
Why do we change the permissions of /bin
too?
find ${WORK_DIR} -type d -exec chmod g+x {} + | ||
|
||
# This will redirect us to the latest stable release. | ||
redirect=$(curl -k https://github.com/openshift/origin/releases/latest) |
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.
Why do we use of -k
/ --insecure
?
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.
Agreed, not needed
/usr/local/bin/generate ${OUTPUT_INVENTORY} | ||
|
||
if [[ -z "${PLAYBOOK}" ]]; then | ||
echo |
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.
Why this?
fi | ||
|
||
# run ansible playbook using generated inventory | ||
ansible-playbook -vvv -i ${OUTPUT_INVENTORY} ${PLAYBOOK} --become --become-user root |
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.
Double space before --become
; missing new line.
Why do we default to -vvv
(and hard code it)?
Why do we set --become-user root
? It is the default.
Why do we need --become
?
@@ -0,0 +1,348 @@ | |||
#!/bin/env python |
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.
Note: the "traditional" path/shebang is #!/usr/bin/env python
, though this should also work on Fedora/RHEL/CentOS.
@@ -0,0 +1,17 @@ | |||
#!/bin/bash -e |
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.
Suggestion: set shell options in the script, not in the shebang -- if the script is executed like /path/to/shell path/to/script
, the -e
flag is suddenly gone.
Also, I recommend:
set -o errexit
set -o nounset
set -o pipefail
This is what we do most often (see shell scripts in Origin), each option for a good reason.
# This file serves as the main entrypoint to the inventory-generator image. | ||
# | ||
# For more information see the documentation: | ||
# https://github.com/juanvallejo/dynamic-inventory/blob/master/README.md |
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.
Update URL?
I did a first pass, but did not review everything. Is it worth having yet another image, what about simply adding a new script to the existing openshift-ansible image? |
cae4164
to
5cee9db
Compare
Was not sure to what extent we wanted to couple this with our existing image. But if it makes more sense to have this functionality as part of it, I can go ahead and update the PR. |
One image sounds good to me. |
00345ba
to
009e570
Compare
@rhcarvalho @sosiouxme still testing, but went ahead and merged |
45c37d0
to
70e2725
Compare
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.
So I know this isn't supposed to be full-featured, but it needs a fair amount more before it will even handle my regular AWS test clusters passably...
(Sorry for the tardiness of my input here)
openshift_hosted_logging_deploy = True | ||
|
||
m = Host("masters") | ||
m.host_alias(common_host_alias) |
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.
What if there is no alias? My hosts don't have aliases.
continue | ||
|
||
n = Host("nodes") | ||
n.host_alias(common_host_alias) |
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.
Likewise; aliases should be optional and I don't think you're going to want to use the same one for all the nodes.
exit(1) | ||
|
||
# set inventory values based on user configuration | ||
common_host_alias = user_config.get('common_host_alias', 'openshiftdevel') |
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.
all hosts default to the same alias? that seems unlikely to work if there is more than one host.
m.host_alias(common_host_alias) | ||
m.address(master_config["masterIP"]) | ||
m.public_host_name(master_public_url) | ||
host_groups["masters"] = HostGroup([m]) |
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.
What if there are multiple masters?
|
||
# connect to remote host using `oc login...` and extract all possible node information | ||
oc = OpenShiftClient() | ||
oc.login(master_public_url, openshift_cluster_user, openshift_cluster_pass) |
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'd really like to be able to just use an existing kubeconfig to connect.
This only handles the use case of a user with a login and password. It's can be a pain to set one of those up and it's likely they want it to be a service account with a revocable auth token. Plus it's possible the master_public_url isn't what they want to use, nor insecure TLS.
Simplest would probably be to use a kubeconfig. It's easy for the user to create one with oc login
. We don't need to recreate oc login
in python.
try: | ||
config_file_obj = open(USER_CONFIG, 'r') | ||
raw_config_file = config_file_obj.read() | ||
user_config = yaml.load(raw_config_file) |
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 the file is empty then this returns None
and all the access below fails. Should check that the result is a dict or just make it an empty one.
-v /tmp/aws/master-config.yaml:/opt/app-root/src/master-config.yaml:Z \ | ||
-e OPTS="-v --become --become-user root" \ | ||
-e PLAYBOOK_FILE=playbooks/byo/config.yml \ | ||
-e GENERATE_INVENTORY=true \ |
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.
need to mention where the inventory gets generated, and they need to specify where Ansible should look for it right?
|
||
INVY = 'generated_hosts' | ||
if len(sys.argv) > 1: | ||
INVY = sys.argv[1] |
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.
should be able to specify full path, not just the name.
Also would like to be able to print to stdout.
|
||
# open new inventory file for writing | ||
try: | ||
inv_file_obj = open(HOME + '/' + INVY, 'w+') |
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.
should be configurable
inv_file_obj.write("ansible_become={}\n".format(ansible_become)) | ||
inv_file_obj.write("openshift_uninstall_images={}\n".format(str(openshift_uninstall_images))) | ||
inv_file_obj.write("openshift_deployment_type={}\n".format(openshift_deployment_type)) | ||
inv_file_obj.write("openshift_install_examples={}\n".format(str(openshift_install_examples))) |
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.
What about all the other stuff from my config file?
openshift_release: 3.6
openshift_image_tag: v3.6.0
openshift_hosted_logging_deploy: True
openshift_logging_image_version: v3.6.0
openshift_disable_check: disk_availability,docker_storage,memory_availability
etc.... i think we want to be able to generate as close to the original file as possible.
11f10f3
to
81a7439
Compare
@sosiouxme thanks for the feedback; review comments addressed. |
40ac162
to
a821120
Compare
[test] |
# runtime user will need to be able to self-insert in /etc/passwd | ||
chmod g+rw /etc/passwd | ||
|
||
# make required config dirs writable | ||
chown ${USER_UID}:0 ${HOME}/.kube/config | ||
chmod a+rw ${HOME}/.kube/config |
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 suspect this file is bind-mounted, and thus this would have an impact on permissions outside of the container...
- specifies where to look for the bind-mounted `master-config.yaml` file in the container | ||
- if omitted or a `null` value is given, its value is defaulted to `/opt/app-root/src/master-config.yaml` | ||
|
||
- `admin_kubeconfig_path` (required): |
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.
How come it is both required and has a default value?!
- username of account capable of listing nodes in a cluster | ||
- used for querying the cluster using `oc` to retrieve additional node information. | ||
|
||
- `master_config_path` (required): |
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.
How come it is both required and has a default value?!
# runtime user will need to be able to self-insert in /etc/passwd | ||
chmod g+rw /etc/passwd | ||
|
||
# make required config dirs writable | ||
chown ${USER_UID}:0 ${HOME}/.kube/config |
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.
These lines ignore admin_kubeconfig_path
, and I think it will only work if admin_kubeconfig_path
has its default value?
|
||
### Build | ||
|
||
`docker build --rm -t openshift/origin-ansible -f images/installer/Dockerfile .` |
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 suspect this must be run from the repository root (to give the correct meaning for .
) and thus we need to note that?
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.
Use triple-backticks for making it a block. Single backtick is used for inline code snippets.
```
docker build --rm -t openshift/origin-ansible -f images/installer/Dockerfile .
```
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.
Hmm, on a second thought, the build process is already described elsewhere, the inventory generation does not need to talk about building images?!
DEFAULT_MASTER_CONFIG_PATH = HOME + '/master-config.yaml' | ||
DEFAULT_ADMIN_KUBECONFIG_PATH = HOME + '/.kube/config' | ||
|
||
INVY_FULL_PATH = HOME + '/generated_hosts' |
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.
INVY
? Sounds funny :-)
@@ -0,0 +1 @@ | |||
../installer/root/etc/inventory-generator-config.yaml |
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.
Why the symlink?
openshift_image_tag: v3.6.0 | ||
openshift_hosted_logging_deploy: null # defaults to "true" if loggingPublicURL is set in master-config.yaml | ||
openshift_logging_image_version: v3.6.0 | ||
openshift_disable_check: disk_availability,docker_storage,memory_availability |
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.
Won't this suggest people to disable these checks unintentionally?
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.
Hm, so I had this for debugging purposes and had meant to take them out :) will update
--- | ||
# meta config | ||
master_config_path: null # defaults to /opt/app-root/src/master-config.yaml | ||
admin_kubeconfig_path: null # defaults to /opt/app-root/src/.kube/config |
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.
How helpful is it to include these?
Feels like the default paths are repeated in many places.
|
||
openshift_release: 3.6 | ||
openshift_image_tag: v3.6.0 | ||
openshift_hosted_logging_deploy: null # defaults to "true" if loggingPublicURL is set in master-config.yaml |
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.
Is it helpful to include this?
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'm thinking with this and admin_kubeconfig_path
above, I could at least default them to their default values instead of null
. I think having these present in the default config file gives a better glance of what can be tweaked
a821120
to
b769288
Compare
b411e30
to
daf81fc
Compare
@sosiouxme thanks for the feedback, review comments addressed. Let's see how ci tests fare this time |
@juanvallejo please rebase and if there are no other changes we can start aos-ci-test and then tag for merge ;) |
daf81fc
to
a705552
Compare
@rhcarvalho thanks, done! |
a705552
to
032858a
Compare
re[test] |
323c429
to
31dd1b4
Compare
31dd1b4
to
c032e4c
Compare
flaked on openshift/origin#8571 re[test] |
aos-ci-test |
Evaluated for openshift ansible test up to 19ea800 |
I found a few things that still needed addressing, so I did that... works for me now. |
continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible/659/) (Base Commit: 665c5c2) (PR Branch Commit: 19ea800) |
... why are the test statuses still yellow? |
Looks like they were run against an old commit, the commit is recorded at the time the aos-ci-test job is queued rather than at the start of the job. So it ran against c032e4c which has since been updated? |
aos-ci-test |
If that isn't complete tomorrow i'm fine to merge this manually based on the results of https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible/659/ |
sigh I just noticed no one had added a merge tag, let me know if this should be reverted. |
@sdodson only reason there was no merge tag was because waiting for aos-ci-test. This is quite low risk so I wouldn't worry about reverting. |
Begin adding https://github.com/juanvallejo/dynamic-inventory as a new sub-pkg under
images/
.the
inventory-generator
is based on this proposalTrello card for the creation of this image: https://trello.com/c/314Df06O
Trello card for integrating this image with
openshift-ansible
: https://trello.com/c/ARPorrvvGoal
The goal behind having this new image is to:
Building
From the root of the
openshift/ansible
directoryImplementation
The reason why (currently) both
master-config.yaml
andadmin.kubeconfig
are needed is because we usemaster-config.yaml
to extract most of the information about hosts that are part of the current deployment, and then useadmin.kubeconfig
to establish a connection with theoc
binary, to retrieve any additional information about any remaining nodes through the output of$ oc get nodes -o yaml
.I am hoping to use this PR and its feedback to mature the contents of this script.
cc @rhcarvalho @brenton @sosiouxme