Skip to content

Commit

Permalink
Upgrading metacontroller to v4.11.22
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek Abouzeid <tarek.abouzeid@teliacompany.com>
  • Loading branch information
tarekabouzeid committed Feb 19, 2025
1 parent c0778ba commit 03fed2f
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Change resyncPeriodSeconds to 1 hour from insane 20 seconds
# Only sync namespaces with pipelines.kubeflow.org/enabled = "true"
apiVersion: metacontroller.k8s.io/v1alpha1
kind: CompositeController
kind: DecoratorController
metadata:
name: kubeflow-pipelines-profile-controller
spec:
generateSelector: true
resyncPeriodSeconds: 3600
parentResource:
apiVersion: v1
resources:
- apiVersion: v1
resource: namespaces
childResources:
labelSelector:
matchLabels:
pipelines.kubeflow.org/enabled: "true"
attachments:
- apiVersion: v1
resource: secrets
updateStrategy:
Expand Down Expand Up @@ -38,4 +38,4 @@ spec:
hooks:
sync:
webhook:
url: http://kubeflow-pipelines-profile-controller/sync
url: http://kubeflow-pipelines-profile-controller/sync
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ commonLabels:
resources:
- service.yaml
- deployment.yaml
- composite-controller.yaml
- decorator-controller.yaml
configMapGenerator:
- name: kubeflow-pipelines-profile-controller-code
files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@ 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):
# parent is a namespace
namespace = parent.get("metadata", {}).get("name")

pipeline_enabled = parent.get("metadata", {}).get(
"labels", {}).get("pipelines.kubeflow.org/enabled")

if pipeline_enabled != "true":
return {"status": {}, "children": []}
return {"status": {}, "attachments": []}

desired_configmap_count = 1
desired_resources = []
Expand All @@ -129,16 +128,16 @@ 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(children["DestinationRule.networking.istio.io/v1alpha3"]) == 1 and
len(children["AuthorizationPolicy.security.istio.io/v1beta1"]) == 1 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
len(attachments["DestinationRule.networking.istio.io/v1alpha3"]) == 1 and
len(attachments["AuthorizationPolicy.security.istio.io/v1beta1"]) == 1 and
"True" or "False"
}

# Generate the desired child object(s).
# Generate the desired attachment object(s).
desired_resources += [
{
"apiVersion": "v1",
Expand Down Expand Up @@ -376,13 +375,13 @@ 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"])
desired = self.sync(observed["object"], observed["attachments"])

self.send_response(200)
self.send_header("Content-type", "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ metadata:
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "list", "watch"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: [""]
resources: ["namespaces/status"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: [""]
resources: ["secrets", "configmaps"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
Expand All @@ -24,3 +27,6 @@ rules:
- apiGroups: ["metacontroller.k8s.io"]
resources: ["compositecontrollers", "controllerrevisions", "decoratorcontrollers"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
Loading

0 comments on commit 03fed2f

Please sign in to comment.