Skip to content

Commit 8253611

Browse files
authored
Cy 2734 cleanup authurl (#112)
* handle this error: kubernetes-client/python#388 * getting started need to figure out what is the right way to handle the delete when there is ambiguety in the resources * finished adding the search for resource ID stuff * works for single resources * works - will fix the tests later * fix testss * trying that * trying to make this work in python3 * final changes
1 parent 134382d commit 8253611

20 files changed

+1096
-384
lines changed

.circleci/config.yml

+100-40
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ executors:
1919
docker:
2020
- image: circleci/python:3.6
2121

22-
centos7:
23-
docker:
24-
- image: amd64/centos:centos7.3.1611
22+
wagon_generator:
23+
machine:
24+
image: ubuntu-1604:201903-01
2525

2626
cloudify-machine:
27-
2827
machine:
2928
image: ubuntu-1604:201903-01
3029

3130

3231
commands:
3332
run_unittest:
3433
steps:
35-
- checkout
34+
- run:
35+
name: "Pull Submodules"
36+
command: |
37+
git submodule init
38+
git submodule update --remote --recursive
3639
- run:
3740
name: install tox
3841
command: pip install --user tox
@@ -71,38 +74,59 @@ commands:
7174
exit 1
7275
fi
7376
74-
generate_wagon:
77+
generate_py27_wagon:
7578
steps:
7679
- run:
77-
name: Install dependencies
78-
command: yum -y install python-devel gcc openssl git libxslt-devel libxml2-devel openldap-devel libffi-devel openssl-devel libvirt-devel
79-
- run:
80-
name: Download pip
81-
command: curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
82-
- run:
83-
name: Install pip
84-
command: python get-pip.py
80+
name: Create Workspace Build directory.
81+
command: mkdir -p workspace/build
8582
- run:
86-
name: Upgrade pip
87-
command: pip install --upgrade pip==9.0.1
83+
name: Build py27 Wagon
84+
command: |
85+
git clone https://github.com/cloudify-cosmo/cloudify-wagon-build-containers.git
86+
docker build -t cloudify-centos-7-wagon-builder cloudify-wagon-build-containers/centos_7
87+
docker run -v ~/project/:/packaging cloudify-centos-7-wagon-builder
8888
- run:
89-
name: Install virtualenv
90-
command: pip install virtualenv==15.1.0
89+
name: copy wagon to workspace
90+
command: cp *.wgn workspace/build/
91+
- persist_to_workspace:
92+
root: workspace
93+
paths:
94+
- build/*
95+
96+
generate_py3_wagon:
97+
steps:
9198
- run:
92-
name: Init virtualenv
93-
command: virtualenv env
99+
name: Create Workspace Build directory.
100+
command: mkdir -p workspace/build
94101
- run:
95-
name: Install wagon
96-
command: pip install wagon==0.3.2
102+
name: Build py3 Wagon
103+
command: |
104+
git clone https://github.com/cloudify-cosmo/cloudify-wagon-build-containers.git
105+
docker build -t cloudify-centos-7-py3-wagon-builder cloudify-wagon-build-containers/centos_7_py3
106+
docker run -v ~/project/:/packaging cloudify-centos-7-py3-wagon-builder
97107
- run:
98-
name: many_linux
99-
command: echo "manylinux1_compatible = False" > "env/bin/_manylinux.py"
108+
name: copy wagon to workspace
109+
command: cp *.wgn workspace/build/
110+
- persist_to_workspace:
111+
root: workspace
112+
paths:
113+
- build/*
114+
115+
116+
generate_rhel_py27_wagon:
117+
steps:
100118
- run:
101-
name: make workspace
119+
name: Create Workspace Build directory.
102120
command: mkdir -p workspace/build
103121
- run:
104-
name: Create wagon
105-
command: source env/bin/activate && wagon create -s . -v -o workspace/build -f -a '--no-cache-dir -c constraints.txt'
122+
name: Build RHEL 27 Wagon
123+
command: |
124+
git clone https://github.com/cloudify-cosmo/cloudify-wagon-build-containers.git
125+
docker build -t cloudify-redhat-7-wagon-builder cloudify-wagon-build-containers/redhat_7 --build-arg USERNAME="$USERNAME" --build-arg PASSWORD="$PASSWORD"
126+
docker run -v ~/project/:/packaging cloudify-redhat-7-wagon-builder
127+
- run:
128+
name: copy wagon to workspace
129+
command: cp *.wgn workspace/build/
106130
- persist_to_workspace:
107131
root: workspace
108132
paths:
@@ -113,7 +137,11 @@ commands:
113137
- run:
114138
name: "Pull Submodules"
115139
command: |
116-
git submodule update --init --recursive
140+
git submodule init
141+
git submodule update --remote --recursive
142+
cd examples/service
143+
git submodule init
144+
git submodule update --remote --recursive
117145
- attach_workspace:
118146
at: workspace
119147
- run:
@@ -124,13 +152,13 @@ commands:
124152
command: pip install -U cloudify==5.0.0 pytest==4.6.3 pyyaml==3.10
125153
- run:
126154
name: download manager docker image
127-
command: wget http://repository.cloudifysource.org/cloudify/5.0.0/ga-release/cloudify-docker-manager-5.0.0.tar
155+
command: wget http://repository.cloudifysource.org/cloudify/5.0.5/ga-release/cloudify-docker-manager-5.0.5.tar
128156
- run:
129157
name: load docker image
130-
command: docker load -i cloudify-docker-manager-5.0.0.tar
158+
command: docker load -i cloudify-docker-manager-5.0.5.tar
131159
- run:
132160
name: retain space by dumping the tar
133-
command: rm cloudify-docker-manager-5.0.0.tar
161+
command: rm cloudify-docker-manager-5.0.5.tar
134162
- run:
135163
name: show images
136164
command: docker images
@@ -179,11 +207,13 @@ jobs:
179207
unittests_py27:
180208
executor: py27
181209
steps:
210+
- checkout
182211
- run_unittest
183212

184213
unittests_py36:
185214
executor: py36
186215
steps:
216+
- checkout
187217
- run_unittest
188218

189219
py3_compat:
@@ -193,10 +223,18 @@ jobs:
193223
- check_py3_compat
194224

195225
wagon:
196-
executor: centos7
226+
executor: wagon_generator
227+
steps:
228+
- checkout
229+
- generate_py27_wagon
230+
# - generate_py3_wagon # TODO: When we have Python3 Manager Integration Test.
231+
232+
rhel_wagon:
233+
executor: wagon_generator
197234
steps:
198235
- checkout
199-
- generate_wagon
236+
- generate_rhel_py27_wagon
237+
200238

201239
integration_tests:
202240
executor: cloudify-machine
@@ -216,28 +254,32 @@ jobs:
216254
workflows:
217255
version: 2
218256
tests:
219-
jobs: &all_jobs
257+
jobs:
220258
- py3_compat
221259
- unittests_py27
222260
- unittests_py36
223261
- wagon:
224262
filters:
225263
branches:
226-
only: /([0-9\.]*\-build|master|dev)/
264+
only: /([0-9\.]*\-build|master)/
265+
- rhel_wagon:
266+
filters:
267+
branches:
268+
only: /([0-9\.]*\-build|master)/
227269
- integration_tests:
228270
requires:
229-
- py3_compat
230-
- unittests_py27
231-
- unittests_py36
232271
- wagon
272+
- rhel_wagon
233273
filters:
234274
branches:
235-
only: /([0-9\.]*\-build|master|dev)/
275+
only: /([0-9\.]*\-build|master)/
236276
- release:
237277
filters:
238278
branches:
239279
only: /master/
240280
requires:
281+
- wagon
282+
- rhel_wagon
241283
- integration_tests
242284
nightly:
243285
triggers:
@@ -247,4 +289,22 @@ workflows:
247289
branches:
248290
only:
249291
- master
250-
jobs: *all_jobs
292+
jobs:
293+
- py3_compat
294+
- unittests_py27
295+
- unittests_py36
296+
- wagon:
297+
filters:
298+
branches:
299+
only: /([0-9\.]*\-build|master)/
300+
- rhel_wagon:
301+
filters:
302+
branches:
303+
only: /([0-9\.]*\-build|master)/
304+
- integration_tests:
305+
requires:
306+
- wagon
307+
- rhel_wagon
308+
filters:
309+
branches:
310+
only: /([0-9\.]*\-build|master)/

CHANGELOG.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@
9696
didnt derived from ResourceBase type.
9797

9898
2.7.2:
99-
- Support Python 3
99+
- Support Python 3
100+
101+
2.8.0:
102+
- Remove trailing slash in URL.
103+
- Support modifying a resource type and number during update workflow.

cloudify_kubernetes/decorators.py

+44-21
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
)
2222
from cloudify.decorators import operation
2323

24+
from ._compat import text_type
2425
from .utils import (generate_traceback_exception,
2526
retrieve_path,
2627
get_node,
2728
get_instance,
2829
NODE_PROPERTY_FILE,
29-
NODE_PROPERTY_FILE_RESOURCE_PATH)
30+
NODE_PROPERTY_FILE_RESOURCE_PATH,
31+
INSTANCE_RUNTIME_PROPERTY_KUBERNETES)
3032
from .k8s import (CloudifyKubernetesClient,
3133
KubernetesApiAuthenticationVariants,
3234
KubernetesApiConfigurationVariants,
@@ -41,7 +43,6 @@
4143
RELATIONSHIP_TYPE_MANAGED_BY_MASTER = (
4244
'cloudify.kubernetes.relationships.managed_by_master'
4345
)
44-
INSTANCE_RUNTIME_PROPERTY_KUBERNETES = 'kubernetes'
4546

4647

4748
def _retrieve_master(resource_instance):
@@ -74,8 +75,10 @@ def _retrieve_property(_ctx, property_name):
7475

7576

7677
def _multidefinition_resource_task(task, definitions, kwargs,
77-
retrieve_mapping, use_existing=False,
78-
cleanup_runtime_properties=False):
78+
retrieve_mapping,
79+
use_existing=False,
80+
cleanup_runtime_properties=False,
81+
resource_state_function=None):
7982
curr_num = 0
8083
# we have several definitions (not one!)
8184
multicalls = len(definitions) > 1
@@ -85,7 +88,7 @@ def _multidefinition_resource_task(task, definitions, kwargs,
8588
# save original path only in case multicalls
8689
origin_path = kwargs[
8790
NODE_PROPERTY_FILE].get(NODE_PROPERTY_FILE_RESOURCE_PATH)
88-
elif NODE_PROPERTY_FILE in ctx.node.properties and multicalls:
91+
elif NODE_PROPERTY_FILE in ctx.node.properties:
8992
# copy origin file name to kwargs
9093
kwargs[NODE_PROPERTY_FILE] = ctx.node.properties[NODE_PROPERTY_FILE]
9194
# save origin path
@@ -101,30 +104,46 @@ def _multidefinition_resource_task(task, definitions, kwargs,
101104
kwargs[NODE_PROPERTY_FILE][NODE_PROPERTY_FILE_RESOURCE_PATH] = (
102105
"{name}#{curr_num}".format(
103106
name=origin_path,
104-
curr_num=str(curr_num)
107+
curr_num=text_type(curr_num)
105108
))
106109
curr_num += 1
110+
107111
# check current state
108112
path = retrieve_path(kwargs)
109-
if path:
113+
resource_id = definition.metadata.get('name')
114+
if path and resource_state_function and resource_id:
115+
current_state = resource_state_function(
116+
resource_id=resource_id, **kwargs)
117+
elif resource_state_function and resource_id:
118+
current_state = resource_state_function(
119+
resource_id=resource_id, **kwargs)
120+
elif path:
110121
current_state = ctx.instance.runtime_properties.get(
111122
INSTANCE_RUNTIME_PROPERTY_KUBERNETES, {}).get(path)
112123
else:
113124
current_state = ctx.instance.runtime_properties.get(
114125
INSTANCE_RUNTIME_PROPERTY_KUBERNETES)
115-
# ignore prexisted state
126+
127+
# ignore pre-existing state
116128
if not use_existing and current_state:
117-
ctx.logger.info("Ignore existing object state")
118-
continue
129+
ctx.logger.info(
130+
"The resource {0} unexpectedly exists. "
131+
"Not executing operation.".format(definition.to_dict()))
132+
ctx.instance.runtime_properties['__perform_task'] = False
119133
# ignore if we dont have any object yet
120-
if use_existing and not current_state:
121-
ctx.logger.info("Ignore unexisted object state")
122-
continue
123-
# finally run
134+
elif use_existing and not current_state:
135+
ctx.logger.info(
136+
"Expected resource {0} to exist, but it does not. "
137+
"Not executing operation.".format(definition.to_dict()))
138+
ctx.instance.runtime_properties['__perform_task'] = False
139+
else:
140+
ctx.instance.runtime_properties['__perform_task'] = True
124141
task(**kwargs)
142+
del ctx.instance.runtime_properties['__perform_task']
125143
# cleanup after successful run
126144
if current_state and cleanup_runtime_properties:
127-
if path:
145+
if path and path in ctx.instance.runtime_properties[
146+
INSTANCE_RUNTIME_PROPERTY_KUBERNETES]:
128147
del ctx.instance.runtime_properties[
129148
INSTANCE_RUNTIME_PROPERTY_KUBERNETES][path]
130149
else:
@@ -143,9 +162,11 @@ def _multidefinition_resource_task(task, definitions, kwargs,
143162

144163
def resource_task(retrieve_resource_definition=None,
145164
retrieve_resources_definitions=None,
146-
retrieve_mapping=None, use_existing=False,
147-
cleanup_runtime_properties=False):
148-
def decorator(task, **kwargs):
165+
retrieve_mapping=None,
166+
use_existing=False,
167+
cleanup_runtime_properties=False,
168+
resource_state_function=None):
169+
def decorator(task, **_):
149170
def wrapper(**kwargs):
150171
try:
151172
definitions = []
@@ -159,7 +180,9 @@ def wrapper(**kwargs):
159180
_multidefinition_resource_task(
160181
task, definitions, kwargs, retrieve_mapping,
161182
use_existing=use_existing,
162-
cleanup_runtime_properties=cleanup_runtime_properties)
183+
cleanup_runtime_properties=cleanup_runtime_properties,
184+
resource_state_function=resource_state_function
185+
)
163186
except (KuberentesMappingNotFoundError,
164187
KuberentesInvalidPayloadClassError,
165188
KuberentesInvalidApiClassError,
@@ -202,7 +225,7 @@ def wrapper(**kwargs):
202225
return decorator
203226

204227

205-
def with_kubernetes_client(function):
228+
def with_kubernetes_client(fn):
206229
def wrapper(**kwargs):
207230
configuration_property = _retrieve_property(
208231
ctx,
@@ -228,7 +251,7 @@ def wrapper(**kwargs):
228251
)
229252
)
230253

231-
function(**kwargs)
254+
fn(**kwargs)
232255
except KuberentesApiInitializationFailedError as e:
233256
error_traceback = generate_traceback_exception()
234257
ctx.logger.error(

0 commit comments

Comments
 (0)