Bläddra i källkod

Replace oc_* module usage with upstream k8s module

Russell Teague 6 år sedan
förälder
incheckning
f2ed434a71

+ 1 - 1
images/installer/Dockerfile

@@ -10,7 +10,7 @@ COPY images/installer/origin-extra-root /
 # install ansible and deps
 RUN INSTALL_PKGS="python-lxml python-dns pyOpenSSL python2-cryptography openssl python2-passlib httpd-tools openssh-clients origin-clients iproute patch" \
  && yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS \
- && EPEL_PKGS="ansible-2.7.8 python2-boto python2-crypto which python2-pip.noarch python2-scandir python2-packaging azure-cli-2.0.46" \
+ && EPEL_PKGS="ansible-2.7.8 python2-boto python2-crypto which python2-pip.noarch python2-scandir python2-packaging azure-cli-2.0.46 python2-openshift" \
  && yum install -y epel-release \
  && yum install -y --setopt=tsflags=nodocs $EPEL_PKGS \
  && if [ "$(uname -m)" == "x86_64" ]; then yum install -y https://sdodson.fedorapeople.org/google-cloud-sdk-183.0.0-3.el7.x86_64.rpm ; fi \

+ 1 - 0
openshift-ansible.spec

@@ -33,6 +33,7 @@ Requires:      python2-crypto
 Requires:      patch
 Requires:      pyOpenSSL
 Requires:      iproute
+Requires:      python2-openshift
 
 %description
 Openshift and Atomic Enterprise Ansible

+ 11 - 11
playbooks/init/basic_facts.yml

@@ -29,24 +29,24 @@
   roles:
   - lib_openshift
   tasks:
-  - oc_obj:
-      name: cluster
-      kind: infrastructures.config.openshift.io
+  - name: Read cluster config
+    k8s_facts:
       kubeconfig: "{{ kubeconfig_path }}"
-      state: present
+      kind: Infrastructure
+      name: cluster
     register: clustercfg
     when: kubeconfig_path is defined
     until:
-    - clustercfg.results is defined
-    - clustercfg.results.returncode is defined
-    - clustercfg.results.returncode == 0
-    - clustercfg.results.results is defined
-    - clustercfg.results.results | length > 0
+    - clustercfg.resources is defined
+    - clustercfg.resources | length > 0
+    - clustercfg.resources[0].status is defined
+    - clustercfg.resources[0].status.apiServerURL is defined
     retries: 36
     delay: 5
     delegate_to: localhost
-  - set_fact:
-      openshift_api_prefix: "{{ clustercfg.results.results[0].status.apiServerURL.split(':')[0:-1] | join(':') }}"
+  - name: Set fact openshift_api_prefix
+    set_fact:
+      openshift_api_prefix: "{{ clustercfg.resources[0].status.apiServerURL.split(':')[0:-1] | join(':') }}"
 
 - name: Set worker openshift_bootstrap_endpoint if not already defined
   hosts: "{{ l_init_fact_hosts | default('nodes') }}:!masters:!bootstrap"

+ 9 - 13
playbooks/openshift-node/scaleup.yml

@@ -25,22 +25,18 @@
   gather_facts: no
   tasks:
   - name: Get release image
-    oc_obj:
+    k8s_facts:
       kubeconfig: "{{ kubeconfig_path }}"
-      state: present
-      kind: clusterversion.config.openshift.io
+      kind: ClusterVersion
       name: version
     register: clusterversion
     until:
-    - clusterversion.results is defined
-    - clusterversion.results.returncode is defined
-    - clusterversion.results.returncode == 0
-    - clusterversion.results.results is defined
-    - clusterversion.results.results | length > 0
-    - clusterversion.results.results[0].status is defined
-    - clusterversion.results.results[0].status.desired is defined
-    - clusterversion.results.results[0].status.desired.image is defined
-    retries: 5
+    - clusterversion.resources is defined
+    - clusterversion.resources | length > 0
+    - clusterversion.resources[0].status is defined
+    - clusterversion.resources[0].status.desired is defined
+    - clusterversion.resources[0].status.desired.image is defined
+    retries: 36
     delay: 5
 
 - name: install nodes
@@ -63,4 +59,4 @@
       name: openshift_node40
       tasks_from: config.yml
     vars:
-      openshift_release_image: "{{ hostvars['localhost'].clusterversion.results.results[0].status.desired.image }}"
+      openshift_release_image: "{{ hostvars['localhost'].clusterversion.resources[0].status.desired.image }}"

+ 21 - 30
test/aws/create_machineset.yml

@@ -1,24 +1,21 @@
 ---
-- name: save machineset to a file
-  copy:
-    content: "{{ item | to_yaml }}"
-    dest: "{{ mktemp.stdout }}/machineset.yaml"
-
 - name: get existing machineset name
   yedit:
     state: list
-    src: "{{ mktemp.stdout }}/machineset.yaml"
+    content: "{{ item | to_yaml }}"
     key: "metadata.name"
   register: machineset_name
 
 - name: edit machineset name
   yedit:
-    src: "{{ mktemp.stdout }}/machineset.yaml"
+    content: "{{ item | to_yaml }}"
     separator: '#'
     state: present
     edits:
     - key: metadata#name
       value: "{{ machineset_name.result }}-centos"
+    - key: metadata#resourceVersion
+      value: ""
     - key: spec#selector#matchLabels#sigs.k8s.io/cluster-api-machineset
       value: "{{ machineset_name.result }}-centos"
     - key: spec#template#metadata#labels#sigs.k8s.io/cluster-api-machineset
@@ -29,41 +26,35 @@
       value: "{{ openshift_aws_scaleup_key }}"
     - key: spec#template#spec#providerSpec#value#ami#id
       value: "{{ openshift_aws_scaleup_ami }}"
+  register: edited_machineset
 
 - name: import machinespec
-  oc_obj:
-    state: present
-    namespace: "openshift-machine-api"
-    kind: machineset
-    name: "{{ machineset_name.result }}-centos"
+  k8s:
     kubeconfig: "{{ kubeconfig_path }}"
-    files:
-    - "{{ mktemp.stdout }}/machineset.yaml"
+    definition: "{{ edited_machineset.result[-1].edit }}"
 
 - name: wait for machine to be created
-  oc_obj:
-    state: list
-    kind: machines.machine.openshift.io
-    namespace: openshift-machine-api
-    selector: "sigs.k8s.io/cluster-api-machineset={{ machineset_name.result }}-centos"
+  k8s_facts:
+    api_version: machine.openshift.io/v1beta1
     kubeconfig: "{{ kubeconfig_path }}"
+    namespace: openshift-machine-api
+    kind: Machine
+    label_selectors:
+    - "sigs.k8s.io/cluster-api-machineset={{ machineset_name.result }}-centos"
   register: new_machine
   retries: 36
   delay: 5
   until:
-  - "'results' in new_machine"
-  - "'results' in new_machine.results"
-  - "new_machine.results.results | length > 0"
-  - "'items' in new_machine.results.results[0]"
-  - "new_machine.results.results[0]['items'] | length > 0"
-  - "'status' in new_machine.results.results[0]['items'][0]"
-  - "'providerStatus' in new_machine.results.results[0]['items'][0]['status']"
-  - "'instanceState' in new_machine.results.results[0]['items'][0]['status']['providerStatus']"
-  - "new_machine.results.results[0]['items'][0]['status']['providerStatus']['instanceState'] == 'running'"
+  - new_machine.resources is defined
+  - new_machine.resources | length > 0
+  - new_machine.resources[0].status is defined
+  - new_machine.resources[0].status.providerStatus is defined
+  - new_machine.resources[0].status.providerStatus.instanceState is defined
+  - new_machine.resources[0].status.providerStatus.instanceState == 'running'
 
 - name: add machine to the inventory
   add_host:
-    name: "{{ new_machine.results.results[0]['items'][0].status.addresses | selectattr('type', 'match', '^InternalIP$') | map(attribute='address') | first }}"
-    node_name: "{{ new_machine.results.results[0]['items'][0].status.addresses | selectattr('type', 'match', '^InternalDNS$') | map(attribute='address') | first }}"
+    name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalIP$') | map(attribute='address') | first }}"
+    node_name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalDNS$') | map(attribute='address') | first }}"
     groups: new_workers
     ansible_ssh_common_args: "-o ProxyCommand=\"ssh -o IdentityFile='{{ openshift_aws_scaleup_key_path | default('/opt/app-root/src/.ssh/id_rsa') }}' -o StrictHostKeyChecking=no -W %h:%p -q core@{{ ssh_bastion }}\""

+ 19 - 25
test/aws/get_machinesets.yml

@@ -1,40 +1,34 @@
 ---
 - name: List existing worker nodes
-  oc_obj:
+  k8s_facts:
     kubeconfig: "{{ kubeconfig_path }}"
-    state: list
-    kind: node
-    selector: "node-role.kubernetes.io/worker"
-  delegate_to: localhost
+    kind: Node
+    label_selectors:
+    - "node-role.kubernetes.io/worker"
   register: pre_scaleup_workers
   until:
-  - pre_scaleup_workers.results is defined
-  - pre_scaleup_workers.results.returncode is defined
-  - pre_scaleup_workers.results.results is defined
-  - pre_scaleup_workers.results.returncode == 0
-  - pre_scaleup_workers.results.results[0]['items'] | length > 0
+  - pre_scaleup_workers.resources is defined
+  - pre_scaleup_workers.resources | length > 0
   retries: 36
   delay: 5
 
-- set_fact:
-    pre_scaleup_workers_name: "{{ pre_scaleup_workers.results.results[0]['items'] |map(attribute='metadata.name') | list }}"
+- name: Set fact pre_scaleup_workers_name
+  set_fact:
+    pre_scaleup_workers_name: "{{ pre_scaleup_workers.resources | map(attribute='metadata.name') | list }}"
 
-- name: get existing worker machinesets
-  oc_obj:
-    state: list
-    kind: machinesets.machine.openshift.io
-    namespace: openshift-machine-api
-    selector: ""
+- name: Get existing worker machinesets
+  k8s_facts:
+    api_version: machine.openshift.io/v1beta1
     kubeconfig: "{{ kubeconfig_path }}"
+    namespace: openshift-machine-api
+    kind: MachineSet
   register: machineset
   until:
-  - machineset.results is defined
-  - machineset.results.returncode is defined
-  - machineset.results.results is defined
-  - machineset.results.returncode == 0
-  - machineset.results.results[0]['items'] | length > 0
+  - machineset.resources is defined
+  - machineset.resources | length > 0
   retries: 36
   delay: 5
 
-- set_fact:
-    pre_scaleup_machineset_names: "{{ machineset.results.results[0]['items'] |map(attribute='metadata.name') | list }}"
+- name: Set fact pre_scaleup_machineset_names
+  set_fact:
+    pre_scaleup_machineset_names: "{{ machineset.resources | map(attribute='metadata.name') | list }}"

+ 17 - 28
test/aws/scaleup.yml

@@ -9,21 +9,12 @@
   hosts: localhost
   connection: local
   tasks:
-  - name: create temp directory
-    command: mktemp -d /tmp/openshift-ansible-XXXXXXX
-    register: mktemp
-    changed_when: False
-  - name: add localhost as master
-    add_host:
-      name: localhost
-      ansible_connection: local
-      groups: masters
-
   - import_tasks: ssh_bastion.yml
+
   - import_tasks: get_machinesets.yml
 
   - include_tasks: create_machineset.yml
-    loop: "{{ machineset.results.results[0]['items'] }}"
+    loop: "{{ machineset.resources }}"
     when:
     - item.status.replicas is defined
     - item.status.replicas != 0
@@ -67,21 +58,18 @@
       name: nfs-utils
       state: present
   - name: Wait for new nodes to be ready
-    oc_obj:
+    k8s_facts:
       kubeconfig: "{{ kubeconfig_path }}"
-      state: list
-      kind: node
+      kind: Node
       name: "{{ node_name }}"
     delegate_to: localhost
     register: new_machine
     until:
-    - new_machine.results is defined
-    - new_machine.results.returncode is defined
-    - new_machine.results.results is defined
-    - new_machine.results.returncode == 0
-    - new_machine.results.results[0].status is defined
-    - new_machine.results.results[0].status.conditions is defined
-    - new_machine.results.results[0].status.conditions | selectattr('type', 'match', '^Ready$') | map(attribute='status') | join | bool == True
+    - new_machine.resources is defined
+    - new_machine.resources | length > 0
+    - new_machine.resources[0].status is defined
+    - new_machine.resources[0].status.conditions is defined
+    - new_machine.resources[0].status.conditions | selectattr('type', 'match', '^Ready$') | map(attribute='status') | join | bool == True
     # Give the node three minutes to come back online.
     retries: 48
     delay: 30
@@ -132,18 +120,19 @@
     with_items: "{{ pre_scaleup_workers_name }}"
 
   - name: remove existing machinesets
-    oc_obj:
-      state: absent
-      kind: machinesets.machine.openshift.io
+    k8s:
+      api_version: machine.openshift.io/v1beta1
+      kubeconfig: "{{ kubeconfig_path }}"
       namespace: openshift-machine-api
+      kind: MachineSet
       name: "{{ item }}"
-      kubeconfig: "{{ kubeconfig_path }}"
+      state: absent
     with_items: "{{ pre_scaleup_machineset_names }}"
 
   - name: Delete CoreOS nodes
-    oc_obj:
+    k8s:
       kubeconfig: "{{ kubeconfig_path }}"
-      state: absent
-      kind: node
+      kind: Node
       name: "{{ item }}"
+      state: absent
     with_items: "{{ pre_scaleup_workers_name }}"

+ 80 - 37
test/aws/ssh_bastion.yml

@@ -1,51 +1,94 @@
 ---
-- name: Create ssh bastion project
-  oc_project:
-    name: openshift-ssh-bastion
-    description: openshift-ssh-bastion
-    node_selector: ""
+- name: Create ssh bastion namespace
+  k8s:
     kubeconfig: "{{ kubeconfig_path }}"
-
-- name: Create ssh keys secret
-  oc_secret:
+    kind: Namespace
+    name: openshift-ssh-bastion
     state: present
-    namespace: openshift-ssh-bastion
-    name: ssh-host-keys
+
+- name: Create ssh bastion keys secret
+  k8s:
     kubeconfig: "{{ kubeconfig_path }}"
-    files:
-    - name: ssh_host_rsa_key
-      path: ../../inventory/dynamic/injected/ssh-privatekey
-    - name: sshd_config
-      path: files/sshd_config
+    resource_definition:
+      apiVersion: v1
+      kind: Secret
+      metadata:
+        name: ssh-host-keys
+        namespace: openshift-ssh-bastion
+      data:
+        ssh_host_rsa_key: "{{ lookup('file', '../../inventory/dynamic/injected/ssh-privatekey') | b64encode }}"
+        sshd_config: "{{ lookup('file', 'files/sshd_config') | b64encode }}"
   no_log: true
 
-- name: Create ssh bastion
-  command: "oc --kubeconfig={{ kubeconfig_path }} apply -f files/"
+- name: Create ssh bastion service
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/01_service.yml
 
-- name: Wait for deployment to rollout
-  command: "oc --kubeconfig={{ kubeconfig_path }} -n openshift-ssh-bastion rollout status deployment ssh-bastion -w"
+- name: Create ssh bastion service account
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/02_serviceaccount.yml
 
-- name: Get ssh bastion address
-  oc_obj:
-    name: ssh-bastion
-    kind: service
+- name: Create ssh bastion role
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/03_role.yml
+
+- name: Create ssh bastion role binding
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/04_rolebinding.yml
+
+- name: Create ssh bastion cluster role
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/05_clusterrole.yml
+
+- name: Create ssh bastion cluster role binding
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/06_clusterrolebinding.yml
+
+- name: Create ssh bastion deployment
+  k8s:
+    kubeconfig: "{{ kubeconfig_path }}"
+    src: files/07_deployment.yml
+
+- name: Wait for ssh bastion deployment to rollout
+  k8s_facts:
+    kubeconfig: "{{ kubeconfig_path }}"
     namespace: openshift-ssh-bastion
+    kind: Deployment
+    name: ssh-bastion
+  register: k8s_result
+  until:
+  - k8s_result.resources is defined
+  - k8s_result.resources | length > 0
+  - k8s_result.resources[0].status is defined
+  - k8s_result.resources[0].status.availableReplicas is defined
+  - k8s_result.resources[0].status.availableReplicas > 0
+  retries: 36
+  delay: 5
+
+- name: Get ssh bastion address
+  k8s_facts:
     kubeconfig: "{{ kubeconfig_path }}"
-    state: present
-  register: svc
+    namespace: openshift-ssh-bastion
+    kind: Service
+    name: ssh-bastion
+  register: k8s_result
   until:
-  - svc.results is defined
-  - svc.results.returncode is defined
-  - svc.results.returncode == 0
-  - svc.results.results is defined
-  - svc.results.results | length > 0
-  - svc.results.results[0].status is defined
-  - svc.results.results[0].status.loadBalancer is defined
-  - svc.results.results[0].status.loadBalancer.ingress is defined
-  - svc.results.results[0].status.loadBalancer.ingress | length > 0
-  - svc.results.results[0].status.loadBalancer.ingress[0].hostname is defined
+  - k8s_result.resources is defined
+  - k8s_result.resources | length > 0
+  - k8s_result.resources[0].status is defined
+  - k8s_result.resources[0].status.loadBalancer is defined
+  - k8s_result.resources[0].status.loadBalancer.ingress is defined
+  - k8s_result.resources[0].status.loadBalancer.ingress | length > 0
+  - k8s_result.resources[0].status.loadBalancer.ingress[0].hostname is defined
   retries: 36
   delay: 5
 
-- set_fact:
-    ssh_bastion: "{{ svc.results.results[0].status.loadBalancer.ingress[0].hostname }}"
+- name: Set fact ssh_bastion
+  set_fact:
+    ssh_bastion: "{{ k8s_result.resources[0].status.loadBalancer.ingress[0].hostname }}"