def assert_termination(self, termination1, termination2): self.preset["termination"] = termination1 assert self.compiled_operation.termination is None assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.termination is not None assert self.compiled_operation.termination.to_dict() == termination1 # Updating the preset self.preset["termination"] = termination2 assert self.compiled_operation.termination.to_dict() == termination1 assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.termination is not None assert self.compiled_operation.termination.to_dict() == termination2
def assert_plugins(self, plugins1, plugins2): self.preset["plugins"] = plugins1 assert self.compiled_operation.plugins is None assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.plugins is not None env = self.compiled_operation.plugins.to_dict() assert env == plugins1 # Updating the preset self.preset["plugins"] = plugins2 plugins = self.compiled_operation.plugins.to_dict() assert plugins == plugins1 assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.plugins is not None plugins = self.compiled_operation.plugins.to_dict() assert plugins == plugins2
def assert_environment(self, environment1, environment2): self.preset["runPatch"]["environment"] = environment1 assert self.compiled_operation.run.environment is None assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.run.environment is not None env = self.compiled_operation.run.environment.to_dict() assert env == environment1 # Updating the preset self.preset["patchStrategy"] = V1PatchStrategy.REPLACE self.preset["runPatch"]["environment"] = environment2 assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.run.environment is not None env = self.compiled_operation.run.environment.to_dict() assert env == environment2
def test_patch_does_not_alter_with_no_preset(self): assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=None, ) == self.compiled_operation )
def test_patch_does_not_alter_with_preset_with_no_environment_or_contexts_or_termination( self, ): assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation )
def test_compile_injects_annotations(self): environment1 = {"annotations": {"anno1": "value1"}} environment2 = {"annotations": {"anno1": "value11"}} self.assert_environment(environment1, environment2) # Updating the preset environment3 = {"annotations": {"anno2": "value2"}} self.preset["runPatch"]["environment"] = environment3 assert (OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation) assert self.compiled_operation.run.environment is not None env = self.compiled_operation.run.environment.to_dict() assert env == {"annotations": {"anno2": "value2"}}
def test_patch_environment_and_termination(self): termination1 = {"maxRetries": 1, "timeout": 1, "ttl": 1} environment1 = { "labels": {"label1": "value1"}, "annotations": {"anno1": "value1"}, "nodeSelector": {"plx": "selector1"}, "affinity": {"podAffinity": {}}, "tolerations": [{"key": "key1", "operator": "Exists"}], "serviceAccountName": "sa1", "imagePullSecrets": ["ps1", "ps2"], "securityContext": {"runAsUser": 1000, "runAsGroup": 3000}, } plugins1 = { "logLevel": "DEBUG", "auth": True, "docker": True, "shm": True, } self.preset["termination"] = termination1 self.preset["runPatch"]["environment"] = environment1 self.preset["plugins"] = plugins1 assert self.compiled_operation.termination is None assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.termination is not None assert self.compiled_operation.termination.to_dict() == termination1 assert self.compiled_operation.run.environment is not None env = self.compiled_operation.run.environment.to_dict() assert env == environment1 assert self.compiled_operation.plugins is not None assert self.compiled_operation.plugins.to_dict() == plugins1 termination2 = {"maxRetries": 10, "timeout": 10, "ttl": 10} environment2 = { "labels": {"label1": "value12"}, "annotations": {"anno1": "value12"}, "nodeSelector": {"plx": "selector12"}, "affinity": {"podAffinity": {"k": "v"}}, "tolerations": [{"key": "key11", "operator": "NotExists"}], "serviceAccountName": "sa2", "imagePullSecrets": ["ps2", "ps22"], "securityContext": {"runAsUser": 100, "runAsGroup": 300}, } plugins2 = { "logLevel": "INFO", "auth": False, "docker": False, "shm": False, } # Updating the preset self.preset["termination"] = termination2 self.preset["runPatch"]["environment"] = environment2 self.preset["plugins"] = plugins2 self.preset["patchStrategy"] = V1PatchStrategy.REPLACE assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.termination is not None assert self.compiled_operation.termination.to_dict() == termination2 assert self.compiled_operation.termination is not None env = self.compiled_operation.run.environment.to_dict() assert env == environment2 assert self.compiled_operation.plugins is not None assert self.compiled_operation.plugins.to_dict() == plugins2 termination3 = {"maxRetries": 15} environment3 = { "labels": {}, "annotations": {}, "nodeSelector": {}, "affinity": {"podAffinity": {"k": "v"}}, "tolerations": [], "securityContext": {"runAsUser": 10, "runAsGroup": 30}, "serviceAccountName": "sa2", "imagePullSecrets": ["ps2", "ps22"], } # Updating the preset self.preset["termination"] = termination3 self.preset["runPatch"]["environment"] = environment3 self.preset["patchStrategy"] = V1PatchStrategy.REPLACE assert ( OperationSpecification.apply_preset( config=self.compiled_operation, preset=self.preset, ) == self.compiled_operation ) assert self.compiled_operation.termination is not None assert self.compiled_operation.termination.to_dict() == { "maxRetries": 15, "timeout": 10, "ttl": 10, } assert self.compiled_operation.termination is not None env = self.compiled_operation.run.environment.to_dict() assert env == environment3 assert self.compiled_operation.plugins is not None assert self.compiled_operation.plugins.to_dict() == plugins2
def resolve_presets(self): for preset in self._get_meta_artifacts_presets(): self.compiled_operation = OperationSpecification.apply_preset( config=self.compiled_operation, preset=preset)