Repository: openshift/openshift-ansible

Issue:
master no longer works with origin 1.3 stable
> The master branch tracks our current work and should be compatible with both Origin master branch and the most recent Origin stable release. Currently that's v1.4 and v1.3.x. 

As of PR #2986 this is no longer the case, as the introduction of `--drain` instead of `--evacuate` fails on < 1.5 (?)

We should work on backwards compatibility for this or note on the project page that you have to have 1.5 to run certain playbooks.

```
# oc adm manage-node node.abc.com --drain --force
Error: unknown flag: --drain
```

##### Version
```
# oc version
oc v1.3.2
kubernetes v1.3.0+52492b4
features: Basic-Auth GSSAPI Kerberos SPNEGO

Server https://cloud.abc.com:8443
openshift v1.3.2
kubernetes v1.3.0+52492b4
```


##### Steps To Reproduce
1. Run the redeploy certificates command using openshift-ansible master and origin 1.3.2 OR run any of the other affected playbooks in PR #2986 

##### Current Result
```
TASK [Drain node] **************************************************************
fatal: [node.abc.com -> master.abc.com]: FAILED! => {"changed": true, "cmd": ["/usr/local/bin/oc", "adm", "--config=/tmp/openshift-ansible-JPhvbC/admin.kubeconfig", "manage-node", "node.abc.com", "--drain", "--force"], "delta": "0:00:00.157084", "end": "2017-01-11 14:32:58.958710", "failed": true, "rc": 1, "start": "2017-01-11 14:32:58.801626", "stderr": "Error: unknown flag: --drain\n\nUsage:\n  oc adm manage-node [options]\n\nExamples:\n\t# Block accepting any pods on given nodes\n\toc adm manage-node <mynode> --schedulable=false\n\n\t# Mark selected nodes as schedulable\n\toc adm manage-node --selector=\"<env=dev>\" --schedulable=true\n\n\t# Migrate selected pods\n\toc adm manage-node <mynode> --evacuate --pod-selector=\"<service=myapp>\"\n\n\t# Migrate selected pods, use a grace period of 60 seconds\n\toc adm manage-node <mynode> --evacuate --grace-period=60 --pod-selector=\"<service=myapp>\"\n\n\t# Migrate selected pods not backed by replication controller\n\toc adm manage-node <mynode> --evacuate --force --pod-selector=\"<service=myapp>\"\n\n\t# Show pods that will be migrated\n\toc adm manage-node <mynode> --evacuate --dry-run --pod-selector=\"<service=myapp>\"\n\n\t# List all pods on given nodes\n\toc adm manage-node <mynode1> <mynode2> --list-pods\n\nOptions:\n      --dry-run=false: Show pods that will be migrated. Optional param for --evacuate\n      --evacuate=false: Migrate all/selected pods on the node.\n      --force=false: Delete pods not backed by replication controller. Optional param for --evacuate\n      --grace-period=30: Grace period (seconds) for pods being deleted. Ignored if negative. Optional param for --evacuate\n      --list-pods=false: List all/selected pods on the node. Printer flags --output, etc. are only valid for this option.\n      --no-headers=false: When using the default output, don't print headers.\n  -o, --output='': Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/release-1.3/docs/user-guide/jsonpath.md].\n      --output-version='': Output the formatted object with the given group version (for ex: 'extensions/v1beta1').\n      --pod-selector='': Label selector to filter pods on the node. Optional param for --evacuate or --list-pods\n      --schedulable=false: Control pod schedulability on the node.\n      --selector='': Label selector to filter nodes. Either pass one/more nodes as arguments or use this node selector\n  -a, --show-all=true: When printing, show all resources (false means hide terminated pods.)\n      --show-labels=false: When printing, show all labels as the last column (default hide labels column)\n      --sort-by='': If non-empty, sort list types using this field specification.  The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.\n      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].\n\nUse \"oc adm options\" for a list of global command-line options (applies to all commands).", "stdout": "", "stdout_lines": [], "warnings": []}
```

##### Expected Result
Success

##### Additional Information
```
ansible-playbook ./playbooks/byo/openshift-cluster/redeploy-certificates.yml --extra-vars="openshift_certificates_redeploy_ca=true"
```
CentOS 7


Discussion:
@djdevin 

> We should work on backwards compatibility for this or note on the project page that you have to have 1.5 to run certain playbooks

I'll submit a PR that conditionalizes the use of `--drain` vs `--evacuate`. Good catch.
I've updated the README.md to reflect that master is relevant to v1.5 and v1.4 now that v1.4 release is eminent and work has moved on to v1.5. Conditional logic to accommodate v1.4 still appreciated. :-)

Resolving patch:
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -867,6 +867,20 @@ def set_deployment_facts_if_unset(facts):
     return facts
 
 
+def set_evacuate_or_drain_option(facts):
+    """OCP before 1.5/3.5 used '--evacuate'. As of 1.5/3.5 OCP uses
+'--drain'. Let's make that a fact for easy reference later.
+    """
+    if facts['common']['version_gte_3_5_or_1_5']:
+        # New-style
+        facts['common']['evacuate_or_drain'] = '--drain'
+    else:
+        # Old-style
+        facts['common']['evacuate_or_drain'] = '--evacuate'
+
+    return facts
+
+
 def set_version_facts_if_unset(facts):
     """ Set version facts. This currently includes common.version and
         common.version_gte_3_1_or_1_1.
@@ -1898,6 +1912,7 @@ def generate_facts(self,
         facts = build_controller_args(facts)
         facts = build_api_server_args(facts)
         facts = set_version_facts_if_unset(facts)
+        facts = set_evacuate_or_drain_option(facts)
         facts = set_dnsmasq_facts_if_unset(facts)
         facts = set_manageiq_facts_if_unset(facts)
         facts = set_aggregate_facts(facts)


Test patch: