Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kind: Function
metadata:
name: function-pythonic
spec:
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.1
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.2
```

### Crossplane V1
Expand All @@ -69,7 +69,7 @@ kind: Function
metadata:
name: function-pythonic
spec:
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.1
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.2
runtimeConfigRef:
name: function-pythonic
--
Expand Down Expand Up @@ -215,6 +215,7 @@ The following functions are provided to create Protobuf structures:
| List | Create a new Protobuf list |
| Unknown | Create a new Protobuf unknown placeholder |
| Yaml | Create a new Protobuf structure from a yaml string |
| YamlAll | Create a new Protobuf list from a yaml string |
| Json | Create a new Protobuf structure from a json string |
| B64Encode | Encode a string into base 64 |
| B64Decode | Decode a string from base 64 |
Expand Down Expand Up @@ -590,7 +591,7 @@ kind: Function
metadata:
name: function-pythonic
spec:
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.1
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.2
runtimeConfigRef:
name: function-pythonic
---
Expand Down
3 changes: 2 additions & 1 deletion crossplane/pythonic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


from .composite import BaseComposite
from .protobuf import append, Map, List, Unknown, Yaml, Json, B64Encode, B64Decode
from .protobuf import append, Map, List, Unknown, Yaml, YamlAll, Json, B64Encode, B64Decode

__all__ = [
'BaseComposite',
Expand All @@ -10,6 +10,7 @@
'List',
'Unknown',
'Yaml',
'YamlAll',
'Json',
'B64Encode',
'B64Decode',
Expand Down
3 changes: 2 additions & 1 deletion crossplane/pythonic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def add_function_arguments(cls, parser):
help='Enable Crossplane V1 compatibility mode',
)

def __init__(self, args):
def __init__(self, args=None):
self.args = args
self.initialize()

Expand All @@ -79,6 +79,7 @@ def initialize_function(self):
logger.setLevel(logging.DEBUG if self.args.debug else logging.INFO)
# Suppress noisy libraries, these can be overriden using --logger-level
logging.getLogger('asyncio').setLevel(logging.INFO)
logging.getLogger('grpc').setLevel(logging.INFO)
logging.getLogger('httpcore').setLevel(logging.INFO)
logging.getLogger('httpx').setLevel(logging.WARNING)
logging.getLogger('kr8s').setLevel(logging.INFO)
Expand Down
10 changes: 5 additions & 5 deletions crossplane/pythonic/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
class FunctionRunner(grpcv1.FunctionRunnerService):
"""A FunctionRunner handles gRPC RunFunctionRequests."""

def __init__(self, debug=False, renderUnknowns=False, crossplane_v1=False):
def __init__(self, renderUnknowns=False, crossplane_v1=False):
"""Create a new FunctionRunner."""
self.debug = debug
self.renderUnknowns = renderUnknowns
self.crossplane_v1 = crossplane_v1
self.clazzes = {}
Expand Down Expand Up @@ -182,7 +181,7 @@ def process_usages(self, composite):
for _, resource in sorted(entry for entry in composite.resources):
dependencies = resource.desired._getDependencies
if dependencies:
if self.debug:
if composite.logger.isEnabledFor(logging.DEBUG):
for destination, source in sorted(dependencies.items()):
destination = self.trimFullName(destination)
source = self.trimFullName(source)
Expand Down Expand Up @@ -278,7 +277,7 @@ def process_unknowns(self, composite):
if resource.unknownsFatal or (resource.unknownsFatal is None and composite.unknownsFatal):
fatalResources.append(name)
fatal = True
if self.debug:
if composite.logger.isEnabledFor(logging.DEBUG):
for destination, source in sorted(unknowns.items()):
destination = self.trimFullName(destination)
source = self.trimFullName(source)
Expand Down Expand Up @@ -319,7 +318,7 @@ def process_unknowns(self, composite):
message = 'All resources are composed'
status = True
result = None
if not self.debug and level:
if not composite.logger.isEnabledFor(logging.DEBUG) and level:
level(message)
composite.conditions.ResourcesComposed(reason, message, status)
if result:
Expand Down Expand Up @@ -378,6 +377,7 @@ def __init__(self):
self.List = pythonic.List
self.Unknown = pythonic.Unknown
self.Yaml = pythonic.Yaml
self.YamlAll = pythonic.YamlAll
self.Json = pythonic.Json
self.B64Encode = pythonic.B64Encode
self.B64Decode = pythonic.B64Decode
2 changes: 1 addition & 1 deletion crossplane/pythonic/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def initialize(self):

async def run(self):
grpc.aio.init_grpc_aio()
grpc_runner = function.FunctionRunner(self.args.debug, self.args.render_unknowns, self.args.crossplane_v1)
grpc_runner = function.FunctionRunner(self.args.render_unknowns, self.args.crossplane_v1)
grpc_server = grpc.aio.server()
grpcv1.add_FunctionRunnerServiceServicer_to_server(grpc_runner, grpc_server)
if self.args.insecure:
Expand Down
7 changes: 7 additions & 0 deletions crossplane/pythonic/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def Yaml(string, readOnly=None):
string = str(string)
return Value(None, None, yaml.safe_load(string), readOnly)

def YamlAll(string, readOnly=None):
if isinstance(string, (FieldMessage, Value)):
if not string:
return string
string = str(string)
return Value(None, None, [document for document in yaml.safe_load_all(string)], readOnly)

def Json(string, readOnly=None):
if isinstance(string, (FieldMessage, Value)):
if not string:
Expand Down
Loading
Loading