|
@@ -2611,6 +2611,21 @@ class Router(OpenShiftCLI):
|
|
|
''' setter for property rolebinding '''
|
|
|
self._rolebinding = config
|
|
|
|
|
|
+ def get_object_by_kind(self, kind):
|
|
|
+ '''return the current object kind by name'''
|
|
|
+ if re.match("^(dc|deploymentconfig)$", kind, flags=re.IGNORECASE):
|
|
|
+ return self.deploymentconfig
|
|
|
+ elif re.match("^(svc|service)$", kind, flags=re.IGNORECASE):
|
|
|
+ return self.service
|
|
|
+ elif re.match("^(sa|serviceaccount)$", kind, flags=re.IGNORECASE):
|
|
|
+ return self.serviceaccount
|
|
|
+ elif re.match("secret", kind, flags=re.IGNORECASE):
|
|
|
+ return self.secret
|
|
|
+ elif re.match("clusterrolebinding", kind, flags=re.IGNORECASE):
|
|
|
+ return self.rolebinding
|
|
|
+
|
|
|
+ return None
|
|
|
+
|
|
|
def get(self):
|
|
|
''' return the self.router_parts '''
|
|
|
self.service = None
|
|
@@ -2761,13 +2776,19 @@ class Router(OpenShiftCLI):
|
|
|
- clusterrolebinding
|
|
|
'''
|
|
|
results = []
|
|
|
+ self.needs_update()
|
|
|
|
|
|
import time
|
|
|
# pylint: disable=maybe-no-member
|
|
|
- for _, oc_data in self.prepared_router.items():
|
|
|
+ for kind, oc_data in self.prepared_router.items():
|
|
|
if oc_data['obj'] is not None:
|
|
|
time.sleep(1)
|
|
|
- results.append(self._create(oc_data['path']))
|
|
|
+ if self.get_object_by_kind(kind) is None:
|
|
|
+ results.append(self._create(oc_data['path']))
|
|
|
+
|
|
|
+ elif oc_data['update']:
|
|
|
+ results.append(self._replace(oc_data['path']))
|
|
|
+
|
|
|
|
|
|
rval = 0
|
|
|
for result in results:
|
|
@@ -2795,17 +2816,15 @@ class Router(OpenShiftCLI):
|
|
|
# pylint: disable=too-many-return-statements,too-many-branches
|
|
|
def needs_update(self):
|
|
|
''' check to see if we need to update '''
|
|
|
- if not self.deploymentconfig or not self.service or not self.serviceaccount or not self.secret:
|
|
|
- return True
|
|
|
-
|
|
|
# ServiceAccount:
|
|
|
# Need to determine changes from the pregenerated ones from the original
|
|
|
# Since these are auto generated, we can skip
|
|
|
skip = ['secrets', 'imagePullSecrets']
|
|
|
- if not Utils.check_def_equal(self.prepared_router['ServiceAccount']['obj'].yaml_dict,
|
|
|
- self.serviceaccount.yaml_dict,
|
|
|
- skip_keys=skip,
|
|
|
- debug=self.verbose):
|
|
|
+ if self.serviceaccount is None or \
|
|
|
+ not Utils.check_def_equal(self.prepared_router['ServiceAccount']['obj'].yaml_dict,
|
|
|
+ self.serviceaccount.yaml_dict,
|
|
|
+ skip_keys=skip,
|
|
|
+ debug=self.verbose):
|
|
|
self.prepared_router['ServiceAccount']['update'] = True
|
|
|
|
|
|
# Secret:
|
|
@@ -2814,10 +2833,11 @@ class Router(OpenShiftCLI):
|
|
|
if not self.secret:
|
|
|
self.prepared_router['Secret']['update'] = True
|
|
|
|
|
|
- if not Utils.check_def_equal(self.prepared_router['Secret']['obj'].yaml_dict,
|
|
|
- self.secret.yaml_dict,
|
|
|
- skip_keys=skip,
|
|
|
- debug=self.verbose):
|
|
|
+ if self.secret is None or \
|
|
|
+ not Utils.check_def_equal(self.prepared_router['Secret']['obj'].yaml_dict,
|
|
|
+ self.secret.yaml_dict,
|
|
|
+ skip_keys=skip,
|
|
|
+ debug=self.verbose):
|
|
|
self.prepared_router['Secret']['update'] = True
|
|
|
|
|
|
# Service:
|
|
@@ -2826,28 +2846,30 @@ class Router(OpenShiftCLI):
|
|
|
port['protocol'] = 'TCP'
|
|
|
|
|
|
skip = ['portalIP', 'clusterIP', 'sessionAffinity', 'type']
|
|
|
- if not Utils.check_def_equal(self.prepared_router['Service']['obj'].yaml_dict,
|
|
|
- self.service.yaml_dict,
|
|
|
- skip_keys=skip,
|
|
|
- debug=self.verbose):
|
|
|
+ if self.service is None or \
|
|
|
+ not Utils.check_def_equal(self.prepared_router['Service']['obj'].yaml_dict,
|
|
|
+ self.service.yaml_dict,
|
|
|
+ skip_keys=skip,
|
|
|
+ debug=self.verbose):
|
|
|
self.prepared_router['Service']['update'] = True
|
|
|
|
|
|
# DeploymentConfig:
|
|
|
# Router needs some exceptions.
|
|
|
# We do not want to check the autogenerated password for stats admin
|
|
|
- if not self.config.config_options['stats_password']['value']:
|
|
|
- for idx, env_var in enumerate(self.prepared_router['DeploymentConfig']['obj'].get(\
|
|
|
- 'spec.template.spec.containers[0].env') or []):
|
|
|
- if env_var['name'] == 'STATS_PASSWORD':
|
|
|
- env_var['value'] = \
|
|
|
- self.deploymentconfig.get('spec.template.spec.containers[0].env[%s].value' % idx)
|
|
|
- break
|
|
|
+ if self.deploymentconfig is not None:
|
|
|
+ if not self.config.config_options['stats_password']['value']:
|
|
|
+ for idx, env_var in enumerate(self.prepared_router['DeploymentConfig']['obj'].get(\
|
|
|
+ 'spec.template.spec.containers[0].env') or []):
|
|
|
+ if env_var['name'] == 'STATS_PASSWORD':
|
|
|
+ env_var['value'] = \
|
|
|
+ self.deploymentconfig.get('spec.template.spec.containers[0].env[%s].value' % idx)
|
|
|
+ break
|
|
|
|
|
|
- # dry-run doesn't add the protocol to the ports section. We will manually do that.
|
|
|
- for idx, port in enumerate(self.prepared_router['DeploymentConfig']['obj'].get(\
|
|
|
- 'spec.template.spec.containers[0].ports') or []):
|
|
|
- if not 'protocol' in port:
|
|
|
- port['protocol'] = 'TCP'
|
|
|
+ # dry-run doesn't add the protocol to the ports section. We will manually do that.
|
|
|
+ for idx, port in enumerate(self.prepared_router['DeploymentConfig']['obj'].get(\
|
|
|
+ 'spec.template.spec.containers[0].ports') or []):
|
|
|
+ if not 'protocol' in port:
|
|
|
+ port['protocol'] = 'TCP'
|
|
|
|
|
|
# These are different when generating
|
|
|
skip = ['dnsPolicy',
|
|
@@ -2858,10 +2880,11 @@ class Router(OpenShiftCLI):
|
|
|
'defaultMode',
|
|
|
]
|
|
|
|
|
|
- if not Utils.check_def_equal(self.prepared_router['DeploymentConfig']['obj'].yaml_dict,
|
|
|
- self.deploymentconfig.yaml_dict,
|
|
|
- skip_keys=skip,
|
|
|
- debug=self.verbose):
|
|
|
+ if self.deploymentconfig is None or \
|
|
|
+ not Utils.check_def_equal(self.prepared_router['DeploymentConfig']['obj'].yaml_dict,
|
|
|
+ self.deploymentconfig.yaml_dict,
|
|
|
+ skip_keys=skip,
|
|
|
+ debug=self.verbose):
|
|
|
self.prepared_router['DeploymentConfig']['update'] = True
|
|
|
|
|
|
# Check if any of the parts need updating, if so, return True
|