Skip to content
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

Decorator controller rewrite #344

Merged
merged 2 commits into from
Oct 6, 2023
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
21 changes: 11 additions & 10 deletions charms/kfp-profile-controller/files/upstream/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def server_factory(visualization_server_image,
Returns an HTTPServer populated with Handler with customized settings
"""
class Controller(BaseHTTPRequestHandler):
def sync(self, parent, children):
def sync(self, parent, attachments):
logger.info("Got new request")

# parent is a namespace
Expand All @@ -155,7 +155,7 @@ def sync(self, parent, children):

if pipeline_enabled != "true":
logger.info(f"Namespace not in scope, no action taken (metadata.labels.pipelines.kubeflow.org/enabled = {pipeline_enabled}, must be 'true')")
return {"status": {}, "children": []}
return {"status": {}, "attachments": []}

desired_configmap_count = 1
desired_resources = []
Expand All @@ -177,13 +177,13 @@ def sync(self, parent, children):
# Compute status based on observed state.
desired_status = {
"kubeflow-pipelines-ready":
len(children["Secret.v1"]) == 1 and
len(children["ConfigMap.v1"]) == desired_configmap_count and
len(children["Deployment.apps/v1"]) == 2 and
len(children["Service.v1"]) == 2 and
len(attachments["Secret.v1"]) == 1 and
len(attachments["ConfigMap.v1"]) == desired_configmap_count and
len(attachments["Deployment.apps/v1"]) == 2 and
len(attachments["Service.v1"]) == 2 and
# TODO CANONICAL: This only works if istio is available. Disabled for now
# len(children["DestinationRule.networking.istio.io/v1alpha3"]) == 1 and
# len(children["AuthorizationPolicy.security.istio.io/v1beta1"]) == 1 and
# len(attachments["DestinationRule.networking.istio.io/v1alpha3"]) == 1 and
# len(attachments["AuthorizationPolicy.security.istio.io/v1beta1"]) == 1 and
"True" or "False"
}

Expand Down Expand Up @@ -470,13 +470,14 @@ def sync(self, parent, children):
},
})

return {"status": desired_status, "children": desired_resources}
return {"status": desired_status, "attachments": desired_resources}

def do_POST(self):
# Serve the sync() function as a JSON webhook.
observed = json.loads(
self.rfile.read(int(self.headers.get("content-length"))))
desired = self.sync(observed["parent"], observed["children"])
logger.info(f"Request is {observed}")
desired = self.sync(observed["object"], observed["attachments"])

self.send_response(200)
self.send_header("Content-type", "application/json")
Expand Down
8 changes: 5 additions & 3 deletions charms/kfp-profile-controller/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

logger = logging.getLogger(__name__)

CompositeController = create_global_resource(
"metacontroller.k8s.io", "v1alpha1", "CompositeController", "compositecontrollers"
DecoratorController = create_global_resource(
"metacontroller.k8s.io", "v1alpha1", "DecoratorController", "decoratorcontrollers"
)
CONTROLLER_PORT = 80
DISABLE_ISTIO_SIDECAR = "false"
Expand All @@ -48,6 +48,7 @@
KFP_IMAGES_VERSION = "2.0.0-alpha.7"
METADATA_GRPC_SERVICE_HOST = "mlmd.kubeflow"
METADATA_GRPC_SERVICE_PORT = "8080"
NAMESPACE_LABEL = "pipelines.kubeflow.org/enabled"
SYNC_CODE_FILE = Path("files/upstream/sync.py")
SYNC_CODE_DESTINATION_PATH = "/hooks/sync.py"

Expand Down Expand Up @@ -91,7 +92,7 @@ def __init__(self, *args):
charm=self,
name="kubernetes:secrets-and-compositecontroller",
resource_templates=K8S_RESOURCE_FILES,
krh_resource_types={Secret, CompositeController},
krh_resource_types={Secret, DecoratorController},
krh_labels=create_charm_default_labels(
self.app.name,
self.model.name,
Expand All @@ -111,6 +112,7 @@ def __init__(self, *args):
)
).decode("utf-8"),
"minio_secret_name": f"{self.model.app.name}-minio-credentials",
"label": NAMESPACE_LABEL,
},
lightkube_client=lightkube.Client(),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: metacontroller.k8s.io/v1alpha1
kind: CompositeController
kind: DecoratorController
metadata:
name: kubeflow-pipelines-profile-controller
spec:
childResources:
attachments:
- apiVersion: v1
resource: secrets
updateStrategy:
Expand All @@ -24,12 +24,14 @@ spec:
resource: poddefaults
updateStrategy:
method: InPlace
generateSelector: true
hooks:
sync:
webhook:
url: {{ sync_webhook_url }}
parentResource:
apiVersion: v1
resources:
- apiVersion: v1
resource: namespaces
labelSelector:
matchExpressions:
- {key: {{ label }}, operator: Exists}
resyncPeriodSeconds: 3600
2 changes: 2 additions & 0 deletions charms/kfp-profile-controller/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ async def test_build_and_deploy(ops_test: OpsTest):
entity_url="metacontroller-operator",
# TODO: Revert once metacontroller stable supports k8s 1.22
channel="latest/edge",
# Remove this config option after the metacontroller-operator is updated to v3
config={"metacontroller-image": "docker.io/metacontrollerio/metacontroller:v3.0.0"},
trust=True,
)

Expand Down
Loading