-
Notifications
You must be signed in to change notification settings - Fork 93
feat: Knative deployment support #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
octonawish-akcodes
wants to merge
11
commits into
spcl:master
Choose a base branch
from
octonawish-akcodes:knative
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5f13fc7
feat: Knative deployment support
octonawish-akcodes f74a2df
Added knative preparation script
octonawish-akcodes 8779f50
added wrappers and updated knative functions
octonawish-akcodes 088ca51
added cached_function
octonawish-akcodes 574cbd7
fixed knative script
octonawish-akcodes ef63c4b
minor fixes
octonawish-akcodes b803caf
updated microbenchmarks and knative integration
octonawish-akcodes 16f1d07
Added docs and regression support
octonawish-akcodes 7b50418
added support for s2i image building instead of pack
octonawish-akcodes c38ded8
fix
octonawish-akcodes 07d38ed
fix knative update functions & updated deployment instructions
octonawish-akcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| from sebs.cache import Cache | ||
| from sebs.faas.config import Credentials, Resources, Config | ||
octonawish-akcodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from sebs.utils import LoggingHandlers | ||
| from sebs.storage.config import MinioConfig | ||
|
|
||
| from typing import cast, Optional | ||
|
|
||
|
|
||
| class KnativeResources(Resources): | ||
| def __init__( | ||
| self, | ||
| registry: Optional[str] = None, | ||
| username: Optional[str] = None, | ||
| password: Optional[str] = None, | ||
| registry_updated: bool = False, | ||
| ): | ||
| super().__init__(name="knative") | ||
| self._docker_registry = registry if registry != "" else None | ||
| self._docker_username = username if username != "" else None | ||
| self._docker_password = password if password != "" else None | ||
| self._registry_updated = registry_updated | ||
| self._storage: Optional[MinioConfig] = None | ||
| self._storage_updated = False | ||
|
|
||
| @staticmethod | ||
| def typename() -> str: | ||
| return "Knative.Resources" | ||
|
|
||
| @property | ||
| def docker_registry(self) -> Optional[str]: | ||
| return self._docker_registry | ||
|
|
||
| @property | ||
| def docker_username(self) -> Optional[str]: | ||
| return self._docker_username | ||
|
|
||
| @property | ||
| def docker_password(self) -> Optional[str]: | ||
| return self._docker_password | ||
|
|
||
| @property | ||
| def storage_config(self) -> Optional[MinioConfig]: | ||
| return self._storage | ||
|
|
||
| @property | ||
| def storage_updated(self) -> bool: | ||
| return self._storage_updated | ||
|
|
||
| @property | ||
| def registry_updated(self) -> bool: | ||
| return self._registry_updated | ||
|
|
||
| @staticmethod | ||
| def initialize(res: Resources, dct: dict): | ||
| ret = cast(KnativeResources, res) | ||
| ret._docker_registry = dct["registry"] | ||
| ret._docker_username = dct["username"] | ||
| ret._docker_password = dct["password"] | ||
|
|
||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @staticmethod | ||
| def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Resources: | ||
|
|
||
| cached_config = cache.get_config("knative") | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ret = KnativeResources() | ||
| if cached_config: | ||
| super(KnativeResources, KnativeResources).initialize( | ||
| ret, cached_config["resources"] | ||
| ) | ||
|
|
||
| # Check for new config - overrides but check if it's different | ||
| if "docker_registry" in config: | ||
|
|
||
| KnativeResources.initialize(ret, config["docker_registry"]) | ||
| ret.logging.info("Using user-provided Docker registry for Knative.") | ||
| ret.logging_handlers = handlers | ||
|
|
||
| # check if there has been an update | ||
| if not ( | ||
| cached_config | ||
| and "resources" in cached_config | ||
| and "docker" in cached_config["resources"] | ||
| and cached_config["resources"]["docker"] == config["docker_registry"] | ||
| ): | ||
| ret._registry_updated = True | ||
|
|
||
| # Load cached values | ||
| elif ( | ||
| cached_config | ||
| and "resources" in cached_config | ||
| and "docker" in cached_config["resources"] | ||
| ): | ||
| KnativeResources.initialize(ret, cached_config["resources"]["docker"]) | ||
| ret.logging_handlers = handlers | ||
| ret.logging.info("Using cached Docker registry for Knative") | ||
| else: | ||
| ret = KnativeResources() | ||
| ret.logging.info("Using default Docker registry for Knative.") | ||
| ret.logging_handlers = handlers | ||
| ret._registry_updated = True | ||
|
|
||
| # Check for new config | ||
| if "storage" in config: | ||
| ret._storage = MinioConfig.deserialize(config["storage"]) | ||
| ret.logging.info("Using user-provided configuration of storage for Knative.") | ||
|
|
||
| # check if there has been an update | ||
| if not ( | ||
| cached_config | ||
| and "resources" in cached_config | ||
| and "storage" in cached_config["resources"] | ||
| and cached_config["resources"]["storage"] == config["storage"] | ||
| ): | ||
| ret.logging.info( | ||
| "User-provided configuration is different from cached storage, " | ||
| "we will update existing Knative actions." | ||
| ) | ||
| ret._storage_updated = True | ||
|
|
||
| # Load cached values | ||
| elif ( | ||
| cached_config | ||
| and "resources" in cached_config | ||
| and "storage" in cached_config["resources"] | ||
| ): | ||
| ret._storage = MinioConfig.deserialize(cached_config["resources"]["storage"]) | ||
| ret.logging.info("Using cached configuration of storage for Knative.") | ||
|
|
||
| return ret | ||
|
|
||
| def update_cache(self, cache: Cache): | ||
| super().update_cache(cache) | ||
| cache.update_config( | ||
| val=self.docker_registry, keys=["knative", "resources", "docker", "registry"] | ||
| ) | ||
| cache.update_config( | ||
| val=self.docker_username, keys=["knative", "resources", "docker", "username"] | ||
| ) | ||
| cache.update_config( | ||
| val=self.docker_password, keys=["knative", "resources", "docker", "password"] | ||
| ) | ||
| if self._storage: | ||
| self._storage.update_cache(["knative", "resources", "storage"], cache) | ||
|
|
||
| def serialize(self) -> dict: | ||
| out: dict = { | ||
| **super().serialize(), | ||
| "docker_registry": self.docker_registry, | ||
| "docker_username": self.docker_username, | ||
| "docker_password": self.docker_password, | ||
| } | ||
| if self._storage: | ||
| out = {**out, "storage": self._storage.serialize()} | ||
| return out | ||
|
|
||
|
|
||
| class KnativeConfig(Config): | ||
| name: str | ||
| cache: Cache | ||
|
|
||
| def __init__(self, config: dict, cache: Cache): | ||
| super().__init__(name="knative") | ||
| self._resources = KnativeResources() | ||
| self.knative_exec = config["knativeExec"] | ||
| self.cache = cache | ||
|
|
||
| @property | ||
| def resources(self) -> KnativeResources: | ||
| return self._resources | ||
|
|
||
| @staticmethod | ||
| def initialize(cfg: Config, dct: dict): | ||
| cfg._region = dct["region"] | ||
|
|
||
| def serialize(self) -> dict: | ||
| return { | ||
| "name": self._name, | ||
| "region": self._region, | ||
| "knativeExec": self.knative_exec, | ||
| "resources": self._resources.serialize(), | ||
| } | ||
|
|
||
| @staticmethod | ||
| def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Config: | ||
| cached_config = cache.get_config("knative") | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resources = cast( | ||
| KnativeResources, KnativeResources.deserialize(config, cache, handlers) | ||
| ) | ||
|
|
||
| res = KnativeConfig(config, cached_config) | ||
| res.logging_handlers = handlers | ||
| res._resources = resources | ||
| return res | ||
octonawish-akcodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def update_cache(self, cache: Cache): | ||
| cache.update_config(val=self.knative_exec, keys=["knative", "knativeExec"]) | ||
| self.resources.update_cache(cache) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import cast, Optional | ||
| from dataclasses import dataclass | ||
|
|
||
| from sebs.benchmark import Benchmark | ||
| from sebs.faas.function import Function, FunctionConfig, Runtime | ||
| from sebs.storage.config import MinioConfig | ||
|
|
||
| @dataclass | ||
| class KnativeFunctionConfig(FunctionConfig): | ||
| docker_image: str = "" | ||
| namespace: str = "default" | ||
| storage: Optional[MinioConfig] = None | ||
| url: str = "" | ||
|
|
||
| @staticmethod | ||
| def deserialize(data: dict) -> KnativeFunctionConfig: | ||
| keys = list(KnativeFunctionConfig.__dataclass_fields__.keys()) | ||
| data = {k: v for k, v in data.items() if k in keys} | ||
| data["runtime"] = Runtime.deserialize(data["runtime"]) | ||
| data["storage"] = MinioConfig.deserialize(data["storage"]) | ||
| return KnativeFunctionConfig(**data) | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def serialize(self) -> dict: | ||
| return self.__dict__ | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @staticmethod | ||
| def from_benchmark(benchmark: Benchmark) -> KnativeFunctionConfig: | ||
| return super(KnativeFunctionConfig, KnativeFunctionConfig)._from_benchmark( | ||
| benchmark, KnativeFunctionConfig | ||
| ) | ||
|
|
||
| class KnativeFunction(Function): | ||
| def __init__( | ||
| self, name: str, benchmark: str, code_package_hash: str, cfg: KnativeFunctionConfig | ||
| ): | ||
| super().__init__(benchmark, name, code_package_hash, cfg) | ||
|
|
||
| @property | ||
| def config(self) -> KnativeFunctionConfig: | ||
| return cast(KnativeFunctionConfig, self._cfg) | ||
|
|
||
| @staticmethod | ||
| def typename() -> str: | ||
| return "Knative.Function" | ||
|
|
||
| def serialize(self) -> dict: | ||
| return {**super().serialize(), "config": self._cfg.serialize()} | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @staticmethod | ||
| def deserialize(cached_config: dict) -> KnativeFunction: | ||
| from sebs.faas.function import Trigger | ||
| from sebs.knative.triggers import KnativeLibraryTrigger, KnativeHTTPTrigger | ||
|
|
||
| cfg = KnativeFunctionConfig.deserialize(cached_config["config"]) | ||
| ret = KnativeFunction( | ||
| cached_config["name"], cached_config["benchmark"], cached_config["hash"], cfg | ||
| ) | ||
| for trigger in cached_config["triggers"]: | ||
| trigger_type = cast( | ||
| Trigger, | ||
| {"Library": KnativeLibraryTrigger, "HTTP": KnativeHTTPTrigger}.get(trigger["type"]), | ||
octonawish-akcodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| assert trigger_type, "Unknown trigger type {}".format(trigger["type"]) | ||
| ret.add_trigger(trigger_type.deserialize(trigger)) | ||
| return ret | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.