Skip to content

Commit 8501bb2

Browse files
author
Patrick J. McNerthney
committed
Rework how self.connection and resource.connection are implemented
1 parent 4b91ebc commit 8501bb2

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ The BaseComposite class provides the following fields for manipulating the Compo
203203
| self.spec | Map | The composite observed spec |
204204
| self.status | Map | The composite desired and observed status, read from observed if not in desired |
205205
| self.conditions | Conditions | The composite desired and observed conditions, read from observed if not in desired |
206-
| self.connection | Connection | The composite desired and observed connection detials, read from observed if not in desired |
207206
| self.events | Events | Returned events against the Composite and optionally on the Claim |
207+
| self.connection | Connection | The composite desired and observed connection detials, read from observed if not in desired |
208208
| self.ready | Boolean | The composite desired ready state |
209209

210210
The BaseComposite also provides access to the following Crossplane Function level features:

crossplane/pythonic/composite.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def __init__(self, request, logger):
4444
self.spec = self.observed.spec
4545
self.status = self.desired.status
4646
self.conditions = Conditions(observed, self.response)
47-
self.connection = Connection(observed, desired)
4847
self.events = Events(self.response)
4948

5049
@property
@@ -67,6 +66,15 @@ def ttl(self, ttl):
6766
else:
6867
raise ValueError('ttl must be an int or float')
6968

69+
@property
70+
def connection(self):
71+
return self.response.desired.composite.connection_details
72+
73+
@connection.setter
74+
def connection(self, connection):
75+
for key, value in connection:
76+
self.response.desired.composite.connection_details[key] = value
77+
7078
@property
7179
def ready(self):
7280
ready = self.desired._parent.ready
@@ -190,7 +198,7 @@ def __init__(self, composite, name):
190198
self.observed = observed.resource
191199
self.desired = desired.resource
192200
self.conditions = Conditions(observed)
193-
self.connection = Connection(observed)
201+
self.connection = observed.connection_details
194202
self.unknownsFatal = None
195203
self.autoReady = None
196204
self.usages = None
@@ -555,38 +563,6 @@ def _find_condition(self, create=False):
555563
return self._conditions._response.conditions.append(condition)
556564

557565

558-
class Connection:
559-
def __init__(self, observed, desired=None):
560-
self.__dict__['_observed'] = observed
561-
self.__dict__['_desired'] = desired
562-
563-
def __bool__(self):
564-
if self._desired is not None and len(self._desired.connection_details) > 0:
565-
return True
566-
if self._observed is not None and len(self._observed.connection_details) > 0:
567-
return True
568-
return False
569-
570-
def __getattr__(self, key):
571-
return self[key]
572-
573-
def __getitem__(self, key):
574-
value = None
575-
if self._desired is not None and key in self._desired.connection_details:
576-
value = self._desired.connection_details[key]
577-
if value is None and key in self._observed.connection_details:
578-
value = self._observed.connection_details[key]
579-
return value
580-
581-
def __setattr__(self, key, value):
582-
self[key] = value
583-
584-
def __setitem__(self, key, value):
585-
if self._desired is None:
586-
raise ValueError('Connection is read only')
587-
self._desired.connection_details[key] = value
588-
589-
590566
class Events:
591567
def __init__(self, response):
592568
self._results = response.results

package/composite-definition.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spec:
2020
spec:
2121
type: object
2222
properties:
23+
parameters:
24+
type: object
25+
x-kubernetes-preserve-unknown-fields: true
2326
composite:
2427
type: string
2528
description: 'A Python module that defines a class with the signature: class Composite(BaseComposite)'

0 commit comments

Comments
 (0)