From a7c5332db05c3c215ea5630b1d7156739784356d Mon Sep 17 00:00:00 2001 From: matst80 Date: Sat, 9 Nov 2024 13:57:09 +0100 Subject: [PATCH] update --- .gitea/workflows/build.yaml | 2 +- deployment.yaml => deployment/deployment.yaml | 41 ++----------------- deployment/roles.yaml | 22 ++++++++++ deployment/scaling.yaml | 11 +++++ k8s-discovery_test.go | 2 +- synced-pool.go | 2 +- 6 files changed, 39 insertions(+), 41 deletions(-) rename deployment.yaml => deployment/deployment.yaml (77%) create mode 100644 deployment/roles.yaml create mode 100644 deployment/scaling.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index bc8a05d..14c1dab 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -13,6 +13,6 @@ jobs: - name: Push to registry run: docker push registry.knatofs.se/go-cart-actor - name: Deploy to Kubernetes - run: kubectl apply -f deployment.yaml -n cart + run: kubectl apply -f deployment/deployment.yaml -n cart - name: Rollout run: kubectl rollout restart deployment/cart-actor -n cart \ No newline at end of file diff --git a/deployment.yaml b/deployment/deployment.yaml similarity index 77% rename from deployment.yaml rename to deployment/deployment.yaml index ec3cae1..e484639 100644 --- a/deployment.yaml +++ b/deployment/deployment.yaml @@ -1,27 +1,3 @@ - -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: cart-discovery -rules: - - apiGroups: [""] # "" indicates the core API group - resources: ["pods","services"] - verbs: ["get", "watch", "list"] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: cart-discovery-binding -subjects: -- kind: ServiceAccount - name: default - namespace: cart - apiGroup: "" -roleRef: - kind: Role - name: cart-discovery - apiGroup: "" ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -37,7 +13,7 @@ spec: metadata: labels: app: cart-actor - pool: cart + actor-pool: cart spec: affinity: nodeAffinity: @@ -56,6 +32,7 @@ spec: server: 10.10.1.10 imagePullSecrets: - name: regcred + serviceAccountName: default containers: - image: registry.knatofs.se/go-cart-actor:latest name: cart-actor @@ -128,16 +105,4 @@ spec: service: name: cart-actor port: - number: 8080 ---- -apiVersion: autoscaling/v1 -kind: HorizontalPodAutoscaler -metadata: - name: cart-scaler -spec: - scaleTargetRef: - kind: Deployment - name: cart-actor - minReplicas: 1 - maxReplicas: 5 - targetCPUUtilizationPercentage: 50 \ No newline at end of file + number: 8080 \ No newline at end of file diff --git a/deployment/roles.yaml b/deployment/roles.yaml new file mode 100644 index 0000000..e99d64f --- /dev/null +++ b/deployment/roles.yaml @@ -0,0 +1,22 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cart-discovery +rules: + - apiGroups: [""] # "" indicates the core API group + resources: ["pods","services"] + verbs: ["get", "watch", "list"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cart-discovery-binding +subjects: +- kind: ServiceAccount + name: default + namespace: cart + apiGroup: "" +roleRef: + kind: ClusterRole + name: cart-discovery + apiGroup: "" \ No newline at end of file diff --git a/deployment/scaling.yaml b/deployment/scaling.yaml new file mode 100644 index 0000000..7c5b082 --- /dev/null +++ b/deployment/scaling.yaml @@ -0,0 +1,11 @@ +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: cart-scaler +spec: + scaleTargetRef: + kind: Deployment + name: cart-actor + minReplicas: 1 + maxReplicas: 5 + targetCPUUtilizationPercentage: 50 \ No newline at end of file diff --git a/k8s-discovery_test.go b/k8s-discovery_test.go index ab053eb..167cffc 100644 --- a/k8s-discovery_test.go +++ b/k8s-discovery_test.go @@ -17,7 +17,7 @@ func TestDiscovery(t *testing.T) { t.Errorf("Error creating client: %v", err) } d := NewK8sDiscovery(client) - res, err := d.DiscoverInNamespace("cart") + res, err := d.DiscoverInNamespace("") if err != nil { t.Errorf("Error discovering: %v", err) } diff --git a/synced-pool.go b/synced-pool.go index af5320c..abd5e09 100644 --- a/synced-pool.go +++ b/synced-pool.go @@ -28,7 +28,7 @@ func (k *K8sDiscovery) Discover() ([]string, error) { } func (k *K8sDiscovery) DiscoverInNamespace(namespace string) ([]string, error) { pods, err := k.client.CoreV1().Pods(namespace).List(k.ctx, metav1.ListOptions{ - //LabelSelector: "pool=cart", + LabelSelector: "actor-pool=cart", }) if err != nil { return nil, err