From e776024fcd87922b24c116d04fa45fa3242740c4 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Wed, 9 Dec 2020 19:27:32 +0100 Subject: [PATCH 01/16] Add support for labels to K8sService --- src/Kinds/K8sService.php | 2 ++ tests/ServiceTest.php | 7 +++++++ tests/yaml/service.yaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Kinds/K8sService.php b/src/Kinds/K8sService.php index acb28047..0dfb3eab 100644 --- a/src/Kinds/K8sService.php +++ b/src/Kinds/K8sService.php @@ -7,12 +7,14 @@ use RenokiCo\PhpK8s\Traits\HasAnnotations; use RenokiCo\PhpK8s\Traits\HasSelector; use RenokiCo\PhpK8s\Traits\HasSpec; +use RenokiCo\PhpK8s\Traits\HasLabels; class K8sService extends K8sResource implements InteractsWithK8sCluster, Watchable { use HasAnnotations; use HasSelector; use HasSpec; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/ServiceTest.php b/tests/ServiceTest.php index dc4ee561..a03a55de 100644 --- a/tests/ServiceTest.php +++ b/tests/ServiceTest.php @@ -12,6 +12,7 @@ public function test_service_build() { $svc = $this->cluster->service() ->setName('nginx') + ->setLabels(['tier' => 'backend']) ->setAnnotations(['nginx/ann' => 'yes']) ->setSelectors(['app' => 'frontend']) ->addPorts([['protocol' => 'TCP', 'port' => 80, 'targetPort' => 80]]) @@ -19,6 +20,7 @@ public function test_service_build() $this->assertEquals('v1', $svc->getApiVersion()); $this->assertEquals('nginx', $svc->getName()); + $this->assertEquals(['tier' => 'backend'], $svc->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $svc->getAnnotations()); $this->assertEquals(['app' => 'frontend'], $svc->getSelectors()); $this->assertEquals([['protocol' => 'TCP', 'port' => 80, 'targetPort' => 80]], $svc->getPorts()); @@ -30,6 +32,7 @@ public function test_service_from_yaml() $this->assertEquals('v1', $svc->getApiVersion()); $this->assertEquals('nginx', $svc->getName()); + $this->assertEquals(['tier' => 'backend'], $svc->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $svc->getAnnotations()); $this->assertEquals(['app' => 'frontend'], $svc->getSelectors()); $this->assertEquals([[ @@ -52,6 +55,7 @@ public function runCreationTests() { $svc = $this->cluster->service() ->setName('nginx') + ->setLabels(['tier' => 'backend']) ->setAnnotations(['nginx/ann' => 'yes']) ->setSelectors(['app' => 'frontend']) ->setPorts([ @@ -70,6 +74,7 @@ public function runCreationTests() $this->assertEquals('v1', $svc->getApiVersion()); $this->assertEquals('nginx', $svc->getName()); + $this->assertEquals(['tier' => 'backend'], $svc->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $svc->getAnnotations()); $this->assertEquals(['app' => 'frontend'], $svc->getSelectors()); $this->assertEquals([[ @@ -100,6 +105,7 @@ public function runGetTests() $this->assertEquals('v1', $svc->getApiVersion()); $this->assertEquals('nginx', $svc->getName()); + $this->assertEquals(['tier' => 'backend'], $svc->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $svc->getAnnotations()); $this->assertEquals(['app' => 'frontend'], $svc->getSelectors()); $this->assertEquals([[ @@ -121,6 +127,7 @@ public function runUpdateTests() $this->assertEquals('v1', $svc->getApiVersion()); $this->assertEquals('nginx', $svc->getName()); + $this->assertEquals(['tier' => 'backend'], $svc->getLabels()); $this->assertEquals([], $svc->getAnnotations()); $this->assertEquals(['app' => 'frontend'], $svc->getSelectors()); $this->assertEquals([[ diff --git a/tests/yaml/service.yaml b/tests/yaml/service.yaml index dfb722e6..c5e70bcf 100644 --- a/tests/yaml/service.yaml +++ b/tests/yaml/service.yaml @@ -2,6 +2,8 @@ apiVersion: v1 kind: Service metadata: name: nginx + labels: + tier: backend annotations: nginx/ann: "yes" spec: From 568f18dee3aad072b636633b2bad836da3d7be15 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Wed, 9 Dec 2020 19:29:46 +0100 Subject: [PATCH 02/16] Fix code style --- src/Kinds/K8sService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kinds/K8sService.php b/src/Kinds/K8sService.php index 0dfb3eab..d6d09854 100644 --- a/src/Kinds/K8sService.php +++ b/src/Kinds/K8sService.php @@ -5,9 +5,9 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; use RenokiCo\PhpK8s\Traits\HasAnnotations; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasSelector; use RenokiCo\PhpK8s\Traits\HasSpec; -use RenokiCo\PhpK8s\Traits\HasLabels; class K8sService extends K8sResource implements InteractsWithK8sCluster, Watchable { From 4a606e49918dab7b4a047bfae667e551573af205 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Wed, 9 Dec 2020 19:34:05 +0100 Subject: [PATCH 03/16] Update documentation --- docs/kinds/Service.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/kinds/Service.md b/docs/kinds/Service.md index 150af5e8..10735a0f 100644 --- a/docs/kinds/Service.md +++ b/docs/kinds/Service.md @@ -7,6 +7,7 @@ ```php $svc = $cluster->service() ->setName('nginx') + ->setLabels(['tier' => 'backend']) ->setSelectors(['app' => 'frontend']) ->setPorts([ ['protocol' => 'TCP', 'port' => 80, 'targetPort' => 80], From 50f95059ca3bfa9ae24606b6509b3ecf2bfd0f65 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 16:50:46 +0100 Subject: [PATCH 04/16] Add labels to K8sIngress --- docs/kinds/Ingress.md | 1 + src/Kinds/K8sIngress.php | 2 ++ tests/IngressTest.php | 8 ++++++++ tests/yaml/ingress_post_1.18.0.yaml | 2 ++ tests/yaml/ingress_pre_1.18.0.yaml | 2 ++ 5 files changed, 15 insertions(+) diff --git a/docs/kinds/Ingress.md b/docs/kinds/Ingress.md index e294a506..add5b358 100644 --- a/docs/kinds/Ingress.md +++ b/docs/kinds/Ingress.md @@ -7,6 +7,7 @@ ```php $ingress = $cluster->ingress() ->setName('nginx') + ->setLabels(['tier' => 'backend']) ->setSelectors(['app' => 'frontend']) ->setRules([[ 'host' => 'nginx.test.com', diff --git a/src/Kinds/K8sIngress.php b/src/Kinds/K8sIngress.php index 7f2d12cf..81e56d60 100644 --- a/src/Kinds/K8sIngress.php +++ b/src/Kinds/K8sIngress.php @@ -5,12 +5,14 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; use RenokiCo\PhpK8s\Traits\HasAnnotations; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasSpec; class K8sIngress extends K8sResource implements InteractsWithK8sCluster, Watchable { use HasAnnotations; use HasSpec; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/IngressTest.php b/tests/IngressTest.php index 62367140..b6c528a6 100644 --- a/tests/IngressTest.php +++ b/tests/IngressTest.php @@ -40,12 +40,14 @@ public function test_ingress_build() { $ing = $this->cluster->ingress() ->setName('nginx') + ->setLabels(['tier' => 'backend']) ->setAnnotations(['nginx/ann' => 'yes']) ->addRules(self::$rules) ->setRules(self::$rules); $this->assertEquals('networking.k8s.io/v1beta1', $ing->getApiVersion()); $this->assertEquals('nginx', $ing->getName()); + $this->assertEquals(['tier' => 'backend'], $ing->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $ing->getAnnotations()); $this->assertEquals(self::$rules, $ing->getRules()); } @@ -60,6 +62,7 @@ public function test_ingress_from_yaml_pre_1_18_0() $this->assertEquals('networking.k8s.io/v1beta1', $ing->getApiVersion()); $this->assertEquals('nginx', $ing->getName()); + $this->assertEquals(['tier' => 'backend'], $ing->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $ing->getAnnotations()); $this->assertEquals(self::$rules, $ing->getRules()); } @@ -74,6 +77,7 @@ public function test_ingress_from_yaml_post_1_18_0() $this->assertEquals('networking.k8s.io/v1beta1', $ing->getApiVersion()); $this->assertEquals('nginx', $ing->getName()); + $this->assertEquals(['tier' => 'backend'], $ing->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $ing->getAnnotations()); $this->assertEquals(self::$rules, $ing->getRules()); } @@ -93,6 +97,7 @@ public function runCreationTests() { $ing = $this->cluster->ingress() ->setName('nginx') + ->setLabels(['tier' => 'backend']) ->setAnnotations(['nginx/ann' => 'yes']) ->setRules(self::$rules); @@ -108,6 +113,7 @@ public function runCreationTests() $this->assertEquals('networking.k8s.io/v1beta1', $ing->getApiVersion()); $this->assertEquals('nginx', $ing->getName()); + $this->assertEquals(['tier' => 'backend'], $ing->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $ing->getAnnotations()); $this->assertEquals(self::$rules, $ing->getRules()); } @@ -135,6 +141,7 @@ public function runGetTests() $this->assertEquals('networking.k8s.io/v1beta1', $ing->getApiVersion()); $this->assertEquals('nginx', $ing->getName()); + $this->assertEquals(['tier' => 'backend'], $ing->getLabels()); $this->assertEquals(['nginx/ann' => 'yes'], $ing->getAnnotations()); $this->assertEquals(self::$rules, $ing->getRules()); } @@ -153,6 +160,7 @@ public function runUpdateTests() $this->assertEquals('networking.k8s.io/v1beta1', $ing->getApiVersion()); $this->assertEquals('nginx', $ing->getName()); + $this->assertEquals(['tier' => 'backend'], $ing->getLabels()); $this->assertEquals([], $ing->getAnnotations()); $this->assertEquals(self::$rules, $ing->getRules()); } diff --git a/tests/yaml/ingress_post_1.18.0.yaml b/tests/yaml/ingress_post_1.18.0.yaml index 9c277c17..99f66198 100644 --- a/tests/yaml/ingress_post_1.18.0.yaml +++ b/tests/yaml/ingress_post_1.18.0.yaml @@ -2,6 +2,8 @@ apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: nginx + labels: + tier: backend annotations: nginx/ann: "yes" spec: diff --git a/tests/yaml/ingress_pre_1.18.0.yaml b/tests/yaml/ingress_pre_1.18.0.yaml index bddac7f5..505356a0 100644 --- a/tests/yaml/ingress_pre_1.18.0.yaml +++ b/tests/yaml/ingress_pre_1.18.0.yaml @@ -2,6 +2,8 @@ apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: nginx + labels: + tier: backend annotations: nginx/ann: "yes" spec: From b584942e7db5635c88167ff3e0d3039cf7e686ec Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 17:01:29 +0100 Subject: [PATCH 05/16] Add labels to Namespace --- src/Kinds/K8sNamespace.php | 2 ++ tests/NamespaceTest.php | 10 ++++++++-- tests/yaml/namespace.yaml | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Kinds/K8sNamespace.php b/src/Kinds/K8sNamespace.php index d9d441bc..f37307c4 100644 --- a/src/Kinds/K8sNamespace.php +++ b/src/Kinds/K8sNamespace.php @@ -4,6 +4,7 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasStatus; use RenokiCo\PhpK8s\Traits\HasStatusPhase; @@ -11,6 +12,7 @@ class K8sNamespace extends K8sResource implements InteractsWithK8sCluster, Watch { use HasStatus; use HasStatusPhase; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/NamespaceTest.php b/tests/NamespaceTest.php index c12ed85b..83756f85 100644 --- a/tests/NamespaceTest.php +++ b/tests/NamespaceTest.php @@ -11,10 +11,12 @@ class NamespaceTest extends TestCase public function test_namespace_build() { $ns = $this->cluster->namespace() - ->setName('production'); + ->setName('production') + ->setLabels(['tier' => 'backend']); $this->assertEquals('v1', $ns->getApiVersion()); $this->assertEquals('production', $ns->getName()); + $this->assertEquals(['tier' => 'backend'], $ns->getLabels()); } public function test_namespace_from_yaml() @@ -23,6 +25,7 @@ public function test_namespace_from_yaml() $this->assertEquals('v1', $ns->getApiVersion()); $this->assertEquals('production', $ns->getName()); + $this->assertEquals(['tier' => 'backend'], $ns->getLabels()); } public function test_namespace_api_interaction() @@ -58,12 +61,14 @@ public function runGetTests() $this->assertTrue($ns->isSynced()); $this->assertEquals('production', $ns->getName()); + $this->assertEquals(['tier' => 'backend'], $ns->getLabels()); } public function runCreationTests() { $ns = $this->cluster->namespace() - ->setName('production'); + ->setName('production') + ->setLabels(['tier' => 'backend']); $this->assertFalse($ns->isSynced()); $this->assertFalse($ns->exists()); @@ -76,6 +81,7 @@ public function runCreationTests() $this->assertInstanceOf(K8sNamespace::class, $ns); $this->assertEquals('production', $ns->getName()); + $this->assertEquals(['tier' => 'backend'], $ns->getLabels()); $ns->refresh(); diff --git a/tests/yaml/namespace.yaml b/tests/yaml/namespace.yaml index 67d15e12..4a9aeb95 100644 --- a/tests/yaml/namespace.yaml +++ b/tests/yaml/namespace.yaml @@ -2,3 +2,5 @@ apiVersion: v1 kind: Namespace metadata: name: production + labels: + tier: backend From e0d37e8885ce21e46a19c0c2b4a2356000f9cf9d Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 17:09:46 +0100 Subject: [PATCH 06/16] Add labels to Secret --- src/Kinds/K8sSecret.php | 3 +++ tests/SecretTest.php | 7 +++++++ tests/yaml/secret.yaml | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/Kinds/K8sSecret.php b/src/Kinds/K8sSecret.php index 9b5cb0f8..26189cab 100644 --- a/src/Kinds/K8sSecret.php +++ b/src/Kinds/K8sSecret.php @@ -4,9 +4,12 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; class K8sSecret extends K8sResource implements InteractsWithK8sCluster, Watchable { + use HasLabels; + /** * The resource Kind parameter. * diff --git a/tests/SecretTest.php b/tests/SecretTest.php index 4044b4dc..c4ec1be1 100644 --- a/tests/SecretTest.php +++ b/tests/SecretTest.php @@ -12,12 +12,14 @@ public function test_secret_build() { $secret = $this->cluster->secret() ->setName('passwords') + ->setLabels(['tier' => 'backend']) ->setData(['root' => 'somevalue']) ->addData('postgres', 'postgres') ->removeData('root'); $this->assertEquals('v1', $secret->getApiVersion()); $this->assertEquals('passwords', $secret->getName()); + $this->assertEquals(['tier' => 'backend'], $secret->getLabels()); $this->assertEquals(['postgres' => base64_encode('postgres')], $secret->getData(false)); $this->assertEquals(['postgres' => 'postgres'], $secret->getData(true)); } @@ -28,6 +30,7 @@ public function test_secret_from_yaml() $this->assertEquals('v1', $secret->getApiVersion()); $this->assertEquals('passwords', $secret->getName()); + $this->assertEquals(['tier' => 'backend'], $secret->getLabels()); $this->assertEquals(['postgres' => base64_encode('postgres')], $secret->getData(false)); $this->assertEquals(['postgres' => 'postgres'], $secret->getData(true)); } @@ -47,6 +50,7 @@ public function runCreationTests() { $secret = $this->cluster->secret() ->setName('passwords') + ->setLabels(['tier' => 'backend']) ->setData(['root' => 'somevalue']) ->addData('postgres', 'postgres') ->removeData('root'); @@ -63,6 +67,7 @@ public function runCreationTests() $this->assertEquals('v1', $secret->getApiVersion()); $this->assertEquals('passwords', $secret->getName()); + $this->assertEquals(['tier' => 'backend'], $secret->getLabels()); $this->assertEquals(['postgres' => base64_encode('postgres')], $secret->getData(false)); $this->assertEquals(['postgres' => 'postgres'], $secret->getData(true)); } @@ -90,6 +95,7 @@ public function runGetTests() $this->assertEquals('v1', $secret->getApiVersion()); $this->assertEquals('passwords', $secret->getName()); + $this->assertEquals(['tier' => 'backend'], $secret->getLabels()); $this->assertEquals(['postgres' => base64_encode('postgres')], $secret->getData(false)); $this->assertEquals(['postgres' => 'postgres'], $secret->getData(true)); } @@ -110,6 +116,7 @@ public function runUpdateTests() $this->assertEquals('v1', $secret->getApiVersion()); $this->assertEquals('passwords', $secret->getName()); + $this->assertEquals(['tier' => 'backend'], $secret->getLabels()); $this->assertEquals(['root' => base64_encode('secret')], $secret->getData(false)); $this->assertEquals(['root' => 'secret'], $secret->getData(true)); } diff --git a/tests/yaml/secret.yaml b/tests/yaml/secret.yaml index 82fb761f..1cab0bfa 100644 --- a/tests/yaml/secret.yaml +++ b/tests/yaml/secret.yaml @@ -2,5 +2,7 @@ apiVersion: v1 kind: Secret metadata: name: passwords + labels: + tier: backend data: postgres: cG9zdGdyZXM= # "postgres" From 253d92d1cea77b134d5fa9cfc59a5dfdaf531f74 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 17:28:35 +0100 Subject: [PATCH 07/16] Add labels to ConfigMap --- docs/kinds/ConfigMap.md | 1 + src/Kinds/K8sConfigMap.php | 3 +++ tests/ConfigMapTest.php | 7 +++++++ tests/yaml/configmap.yaml | 2 ++ 4 files changed, 13 insertions(+) diff --git a/docs/kinds/ConfigMap.md b/docs/kinds/ConfigMap.md index 4771d076..fa04ca13 100644 --- a/docs/kinds/ConfigMap.md +++ b/docs/kinds/ConfigMap.md @@ -7,6 +7,7 @@ ```php $cm = $cluster->configmap() ->setName('certificates') + ->setLabels(['tier' => 'backend']) ->setData([ 'key.pem' => '...', 'ca.pem' => '...', diff --git a/src/Kinds/K8sConfigMap.php b/src/Kinds/K8sConfigMap.php index 44ab0c52..f9edb92e 100644 --- a/src/Kinds/K8sConfigMap.php +++ b/src/Kinds/K8sConfigMap.php @@ -4,9 +4,12 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; class K8sConfigMap extends K8sResource implements InteractsWithK8sCluster, Watchable { + use HasLabels; + /** * The resource Kind parameter. * diff --git a/tests/ConfigMapTest.php b/tests/ConfigMapTest.php index d51cf44f..8fa3ea2f 100644 --- a/tests/ConfigMapTest.php +++ b/tests/ConfigMapTest.php @@ -12,12 +12,14 @@ public function test_config_map_build() { $cm = $this->cluster->configmap() ->setName('settings') + ->setLabels(['tier' => 'backend']) ->setData(['somekey' => 'somevalue']) ->addData('key2', 'val2') ->removeData('somekey'); $this->assertEquals('v1', $cm->getApiVersion()); $this->assertEquals('settings', $cm->getName()); + $this->assertEquals(['tier' => 'backend'], $cm->getLabels()); $this->assertEquals(['key2' => 'val2'], $cm->getData()); } @@ -27,6 +29,7 @@ public function test_config_map_from_yaml() $this->assertEquals('v1', $cm->getApiVersion()); $this->assertEquals('settings', $cm->getName()); + $this->assertEquals(['tier' => 'backend'], $cm->getLabels()); $this->assertEquals(['key2' => 'val2'], $cm->getData()); } @@ -45,6 +48,7 @@ public function runCreationTests() { $cm = $this->cluster->configmap() ->setName('settings') + ->setLabels(['tier' => 'backend']) ->setData(['somekey' => 'somevalue']) ->addData('key2', 'val2') ->removeData('somekey'); @@ -61,6 +65,7 @@ public function runCreationTests() $this->assertEquals('v1', $cm->getApiVersion()); $this->assertEquals('settings', $cm->getName()); + $this->assertEquals(['tier' => 'backend'], $cm->getLabels()); $this->assertEquals(['key2' => 'val2'], $cm->getData()); $this->assertEquals('val2', $cm->getData('key2')); } @@ -88,6 +93,7 @@ public function runGetTests() $this->assertEquals('v1', $cm->getApiVersion()); $this->assertEquals('settings', $cm->getName()); + $this->assertEquals(['tier' => 'backend'], $cm->getLabels()); $this->assertEquals(['key2' => 'val2'], $cm->getData()); $this->assertEquals('val2', $cm->getData('key2')); } @@ -107,6 +113,7 @@ public function runUpdateTests() $this->assertEquals('v1', $cm->getApiVersion()); $this->assertEquals('settings', $cm->getName()); + $this->assertEquals(['tier' => 'backend'], $cm->getLabels()); $this->assertEquals(['newkey' => 'newval'], $cm->getData()); $this->assertEquals('newval', $cm->getData('newkey')); } diff --git a/tests/yaml/configmap.yaml b/tests/yaml/configmap.yaml index 57026c70..6dfe2839 100644 --- a/tests/yaml/configmap.yaml +++ b/tests/yaml/configmap.yaml @@ -2,5 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: settings + labels: + tier: backend data: key2: val2 From cadcdd88d1921bc895ade0e048b7e0f19416a6e3 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 21:19:31 +0100 Subject: [PATCH 08/16] Add labels to ServiceAccount --- src/Kinds/K8sServiceAccount.php | 3 +++ tests/ServiceAccountTest.php | 8 ++++++++ tests/yaml/serviceaccount.yaml | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/Kinds/K8sServiceAccount.php b/src/Kinds/K8sServiceAccount.php index 02900ef3..2a530bfb 100644 --- a/src/Kinds/K8sServiceAccount.php +++ b/src/Kinds/K8sServiceAccount.php @@ -4,9 +4,12 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; class K8sServiceAccount extends K8sResource implements InteractsWithK8sCluster, Watchable { + use HasLabels; + /** * The resource Kind parameter. * diff --git a/tests/ServiceAccountTest.php b/tests/ServiceAccountTest.php index df4b99a4..9d946ee3 100644 --- a/tests/ServiceAccountTest.php +++ b/tests/ServiceAccountTest.php @@ -16,12 +16,14 @@ public function test_service_account_build() $sa = $this->cluster->serviceAccount() ->setName('user1') + ->setLabels(['tier' => 'backend']) ->addSecrets([$secret]) ->setSecrets([$secret]) ->addPulledSecrets(['postgres']); $this->assertEquals('v1', $sa->getApiVersion()); $this->assertEquals('user1', $sa->getName()); + $this->assertEquals(['tier' => 'backend'], $sa->getLabels()); $this->assertEquals([['name' => $secret->getName()]], $sa->getSecrets()); $this->assertEquals([['name' => 'postgres']], $sa->getImagePullSecrets()); } @@ -30,12 +32,14 @@ public function test_service_account_from_yaml() { $secret = $this->cluster->secret() ->setName('passwords') + ->setLabels(['tier' => 'backend']) ->addData('postgres', 'postgres'); $sa = $this->cluster->fromYamlFile(__DIR__.'/yaml/serviceaccount.yaml'); $this->assertEquals('v1', $sa->getApiVersion()); $this->assertEquals('user1', $sa->getName()); + $this->assertEquals(['tier' => 'backend'], $sa->getLabels()); $this->assertEquals([['name' => $secret->getName()]], $sa->getSecrets()); $this->assertEquals([['name' => 'postgres']], $sa->getImagePullSecrets()); } @@ -59,6 +63,7 @@ public function runCreationTests() $sa = $this->cluster->serviceAccount() ->setName('user1') + ->setLabels(['tier' => 'backend']) ->addSecrets([$secret]) ->setSecrets([$secret]) ->addPulledSecrets(['postgres']); @@ -76,6 +81,7 @@ public function runCreationTests() $this->assertEquals('v1', $sa->getApiVersion()); $this->assertEquals('user1', $sa->getName()); + $this->assertEquals(['tier' => 'backend'], $sa->getLabels()); $this->assertEquals([['name' => $secret->getName()]], $sa->getSecrets()); $this->assertEquals([['name' => 'postgres']], $sa->getImagePullSecrets()); } @@ -104,6 +110,7 @@ public function runGetTests() $this->assertEquals('v1', $sa->getApiVersion()); $this->assertEquals('user1', $sa->getName()); + $this->assertEquals(['tier' => 'backend'], $sa->getLabels()); $this->assertEquals(['name' => $secret->getName()], $sa->getSecrets()[0]); $this->assertEquals([['name' => 'postgres']], $sa->getImagePullSecrets()); } @@ -123,6 +130,7 @@ public function runUpdateTests() $this->assertEquals('v1', $sa->getApiVersion()); $this->assertEquals('user1', $sa->getName()); + $this->assertEquals(['tier' => 'backend'], $sa->getLabels()); $this->assertEquals(['name' => $secret->getName()], $sa->getSecrets()[0]); $this->assertEquals([['name' => 'postgres'], ['name' => 'postgres2']], $sa->getImagePullSecrets()); } diff --git a/tests/yaml/serviceaccount.yaml b/tests/yaml/serviceaccount.yaml index c9d8c399..4e28f26b 100644 --- a/tests/yaml/serviceaccount.yaml +++ b/tests/yaml/serviceaccount.yaml @@ -2,6 +2,8 @@ apiVersion: v1 kind: ServiceAccount metadata: name: user1 + labels: + tier: backend secrets: - name: passwords imagePullSecrets: From 56cdf6120454b11dac52f69848cc0748a7528b9f Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 21:24:54 +0100 Subject: [PATCH 09/16] Add labels to ClusterRoleBinding --- src/Kinds/K8sClusterRoleBinding.php | 4 ++++ tests/ClusterRoleBindingTest.php | 7 +++++++ tests/yaml/clusterrolebinding.yaml | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/Kinds/K8sClusterRoleBinding.php b/src/Kinds/K8sClusterRoleBinding.php index dc1e4727..da227eb1 100644 --- a/src/Kinds/K8sClusterRoleBinding.php +++ b/src/Kinds/K8sClusterRoleBinding.php @@ -2,8 +2,12 @@ namespace RenokiCo\PhpK8s\Kinds; +use RenokiCo\PhpK8s\Traits\HasLabels; + class K8sClusterRoleBinding extends K8sRoleBinding { + use HasLabels; + /** * The resource Kind parameter. * diff --git a/tests/ClusterRoleBindingTest.php b/tests/ClusterRoleBindingTest.php index e91f7e74..1b949413 100644 --- a/tests/ClusterRoleBindingTest.php +++ b/tests/ClusterRoleBindingTest.php @@ -30,12 +30,14 @@ public function test_cluster_role_binding_build() $crb = $this->cluster->clusterRoleBinding() ->setName('user-binding') + ->setLabels(['tier' => 'backend']) ->setRole($cr) ->addSubjects([$subject]) ->setSubjects([$subject]); $this->assertEquals('rbac.authorization.k8s.io/v1', $crb->getApiVersion()); $this->assertEquals('user-binding', $crb->getName()); + $this->assertEquals(['tier' => 'backend'], $crb->getLabels()); $this->assertEquals([$subject], $crb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole()); } @@ -62,6 +64,7 @@ public function test_cluster_role_binding_from_yaml() $this->assertEquals('rbac.authorization.k8s.io/v1', $crb->getApiVersion()); $this->assertEquals('user-binding', $crb->getName()); + $this->assertEquals(['tier' => 'backend'], $crb->getLabels()); $this->assertEquals([$subject], $crb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole()); } @@ -97,6 +100,7 @@ public function runCreationTests() $crb = $this->cluster->clusterRoleBinding() ->setName('user-binding') + ->setLabels(['tier' => 'backend']) ->setRole($cr) ->addSubjects([$subject]) ->setSubjects([$subject]); @@ -114,6 +118,7 @@ public function runCreationTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $crb->getApiVersion()); $this->assertEquals('user-binding', $crb->getName()); + $this->assertEquals(['tier' => 'backend'], $crb->getLabels()); $this->assertEquals([$subject], $crb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole()); } @@ -147,6 +152,7 @@ public function runGetTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $crb->getApiVersion()); $this->assertEquals('user-binding', $crb->getName()); + $this->assertEquals(['tier' => 'backend'], $crb->getLabels()); $this->assertEquals([$subject], $crb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole()); } @@ -171,6 +177,7 @@ public function runUpdateTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $crb->getApiVersion()); $this->assertEquals('user-binding', $crb->getName()); + $this->assertEquals(['tier' => 'backend'], $crb->getLabels()); $this->assertEquals([$subject], $crb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole()); } diff --git a/tests/yaml/clusterrolebinding.yaml b/tests/yaml/clusterrolebinding.yaml index d3749022..01062d42 100644 --- a/tests/yaml/clusterrolebinding.yaml +++ b/tests/yaml/clusterrolebinding.yaml @@ -2,6 +2,8 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: user-binding + labels: + tier: backend roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole From 86e0855248c0763d6f686a1e5c7f1cf5449c4b36 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 21:33:07 +0100 Subject: [PATCH 10/16] Add labels to HorizontalPodAutoscaler --- src/Kinds/K8sHorizontalPodAutoscaler.php | 2 ++ tests/HorizontalPodAutoscalerTest.php | 7 +++++++ tests/yaml/hpa.yaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Kinds/K8sHorizontalPodAutoscaler.php b/src/Kinds/K8sHorizontalPodAutoscaler.php index 165fdfe0..8e2e96fc 100644 --- a/src/Kinds/K8sHorizontalPodAutoscaler.php +++ b/src/Kinds/K8sHorizontalPodAutoscaler.php @@ -6,6 +6,7 @@ use RenokiCo\PhpK8s\Contracts\Scalable; use RenokiCo\PhpK8s\Contracts\Watchable; use RenokiCo\PhpK8s\Instances\ResourceMetric; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasSpec; use RenokiCo\PhpK8s\Traits\HasStatus; use RenokiCo\PhpK8s\Traits\HasStatusConditions; @@ -15,6 +16,7 @@ class K8sHorizontalPodAutoscaler extends K8sResource implements InteractsWithK8s use HasSpec; use HasStatus; use HasStatusConditions; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/HorizontalPodAutoscalerTest.php b/tests/HorizontalPodAutoscalerTest.php index 30f97ad9..bd762807 100644 --- a/tests/HorizontalPodAutoscalerTest.php +++ b/tests/HorizontalPodAutoscalerTest.php @@ -35,6 +35,7 @@ public function test_horizontal_pod_autoscaler_build() $hpa = $this->cluster->horizontalPodAutoscaler() ->setName('mysql-hpa') + ->setLabels(['tier' => 'backend']) ->setResource($dep) ->addMetrics([$cpuMetric]) ->setMetrics([$cpuMetric]) @@ -43,6 +44,7 @@ public function test_horizontal_pod_autoscaler_build() $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); + $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); $this->assertEquals(1, $hpa->getMinReplicas()); $this->assertEquals(10, $hpa->getMaxReplicas()); @@ -74,6 +76,7 @@ public function test_horizontal_pod_autoscaler_from_yaml() $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); + $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); $this->assertEquals(1, $hpa->getMinReplicas()); $this->assertEquals(10, $hpa->getMaxReplicas()); @@ -120,6 +123,7 @@ public function runCreationTests() $hpa = $this->cluster->horizontalPodAutoscaler() ->setName('mysql-hpa') + ->setLabels(['tier' => 'backend']) ->setResource($dep) ->addMetrics([$cpuMetric]) ->min(1) @@ -139,6 +143,7 @@ public function runCreationTests() $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); + $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); $this->assertEquals(1, $hpa->getMinReplicas()); $this->assertEquals(10, $hpa->getMaxReplicas()); @@ -200,6 +205,7 @@ public function runGetTests() $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); + $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); $this->assertEquals(1, $hpa->getMinReplicas()); $this->assertEquals(10, $hpa->getMaxReplicas()); @@ -227,6 +233,7 @@ public function runUpdateTests() $this->assertEquals('autoscaling/v2beta2', $hpa->getApiVersion()); $this->assertEquals('mysql-hpa', $hpa->getName()); + $this->assertEquals(['tier' => 'backend'], $hpa->getLabels()); $this->assertEquals([$cpuMetric->toArray()], $hpa->getMetrics()); $this->assertEquals(1, $hpa->getMinReplicas()); $this->assertEquals(6, $hpa->getMaxReplicas()); diff --git a/tests/yaml/hpa.yaml b/tests/yaml/hpa.yaml index 3b5c9dc8..fe2013a4 100644 --- a/tests/yaml/hpa.yaml +++ b/tests/yaml/hpa.yaml @@ -2,6 +2,8 @@ apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: mysql-hpa + labels: + tier: backend spec: scaleTargetRef: kind: Deployment From 70d870c86371c7a3fe58b63f78750c68e0d93f74 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 21:42:15 +0100 Subject: [PATCH 11/16] Add labels to StorageClass --- src/Kinds/K8sStorageClass.php | 3 +++ tests/StorageClassTest.php | 7 +++++++ tests/yaml/storageclass.yaml | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/Kinds/K8sStorageClass.php b/src/Kinds/K8sStorageClass.php index d9c6205c..4b17c9a7 100644 --- a/src/Kinds/K8sStorageClass.php +++ b/src/Kinds/K8sStorageClass.php @@ -4,9 +4,12 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; class K8sStorageClass extends K8sResource implements InteractsWithK8sCluster, Watchable { + use HasLabels; + /** * The resource Kind parameter. * diff --git a/tests/StorageClassTest.php b/tests/StorageClassTest.php index 8223e1e3..ecd96bdd 100644 --- a/tests/StorageClassTest.php +++ b/tests/StorageClassTest.php @@ -12,12 +12,14 @@ public function test_storage_class_build() { $sc = $this->cluster->storageClass() ->setName('io1') + ->setLabels(['tier' => 'backend']) ->setProvisioner('csi.aws.amazon.com') ->setParameters(['type' => 'io1', 'iopsPerGB' => 10]) ->setMountOptions(['debug']); $this->assertEquals('storage.k8s.io/v1', $sc->getApiVersion()); $this->assertEquals('io1', $sc->getName()); + $this->assertEquals(['tier' => 'backend'], $sc->getLabels()); $this->assertEquals('csi.aws.amazon.com', $sc->getProvisioner()); $this->assertEquals(['type' => 'io1', 'iopsPerGB' => 10], $sc->getParameters()); $this->assertEquals(['debug'], $sc->getMountOptions()); @@ -29,6 +31,7 @@ public function test_storage_class_from_yaml() $this->assertEquals('storage.k8s.io/v1', $sc->getApiVersion()); $this->assertEquals('io1', $sc->getName()); + $this->assertEquals(['tier' => 'backend'], $sc->getLabels()); $this->assertEquals('csi.aws.amazon.com', $sc->getProvisioner()); $this->assertEquals(['type' => 'io1', 'iopsPerGB' => 10], $sc->getParameters()); $this->assertEquals(['debug'], $sc->getMountOptions()); @@ -49,6 +52,7 @@ public function runCreationTests() { $sc = $this->cluster->storageClass() ->setName('io1') + ->setLabels(['tier' => 'backend']) ->setProvisioner('csi.aws.amazon.com') ->setParameters(['type' => 'io1', 'iopsPerGB' => '10']) ->setMountOptions(['debug']); @@ -65,6 +69,7 @@ public function runCreationTests() $this->assertEquals('storage.k8s.io/v1', $sc->getApiVersion()); $this->assertEquals('io1', $sc->getName()); + $this->assertEquals(['tier' => 'backend'], $sc->getLabels()); $this->assertEquals('csi.aws.amazon.com', $sc->getProvisioner()); $this->assertEquals(['type' => 'io1', 'iopsPerGB' => 10], $sc->getParameters()); $this->assertEquals(['debug'], $sc->getMountOptions()); @@ -93,6 +98,7 @@ public function runGetTests() $this->assertEquals('storage.k8s.io/v1', $sc->getApiVersion()); $this->assertEquals('io1', $sc->getName()); + $this->assertEquals(['tier' => 'backend'], $sc->getLabels()); $this->assertEquals('csi.aws.amazon.com', $sc->getProvisioner()); $this->assertEquals(['type' => 'io1', 'iopsPerGB' => 10], $sc->getParameters()); $this->assertEquals(['debug'], $sc->getMountOptions()); @@ -112,6 +118,7 @@ public function runUpdateTests() $this->assertEquals('storage.k8s.io/v1', $sc->getApiVersion()); $this->assertEquals('io1', $sc->getName()); + $this->assertEquals(['tier' => 'backend'], $sc->getLabels()); $this->assertEquals(['debug'], $sc->getAttribute('mountOptions')); $this->assertEquals(['type' => 'io1', 'iopsPerGB' => '10'], $sc->getParameters()); $this->assertEquals(['debug'], $sc->getMountOptions()); diff --git a/tests/yaml/storageclass.yaml b/tests/yaml/storageclass.yaml index 28e32154..e331cdc4 100644 --- a/tests/yaml/storageclass.yaml +++ b/tests/yaml/storageclass.yaml @@ -2,6 +2,8 @@ apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: io1 + labels: + tier: backend provisioner: csi.aws.amazon.com parameters: type: io1 From aaa62560744fa3da7edbb7a15f2c5c57b2a7d357 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Thu, 10 Dec 2020 21:47:36 +0100 Subject: [PATCH 12/16] Add labels to Role --- src/Kinds/K8sRole.php | 2 ++ tests/RoleTest.php | 7 +++++++ tests/yaml/role.yaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Kinds/K8sRole.php b/src/Kinds/K8sRole.php index 2d55e7e3..16ed83ff 100644 --- a/src/Kinds/K8sRole.php +++ b/src/Kinds/K8sRole.php @@ -4,11 +4,13 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasRules; class K8sRole extends K8sResource implements InteractsWithK8sCluster, Watchable { use HasRules; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/RoleTest.php b/tests/RoleTest.php index e4ebdf5c..5c328eae 100644 --- a/tests/RoleTest.php +++ b/tests/RoleTest.php @@ -20,10 +20,12 @@ public function test_role_build() $role = $this->cluster->role() ->setName('admin') + ->setLabels(['tier' => 'backend']) ->addRules([$rule]); $this->assertEquals('rbac.authorization.k8s.io/v1', $role->getApiVersion()); $this->assertEquals('admin', $role->getName()); + $this->assertEquals(['tier' => 'backend'], $role->getLabels()); $this->assertEquals([$rule], $role->getRules()); } @@ -39,6 +41,7 @@ public function test_role_from_yaml() $this->assertEquals('rbac.authorization.k8s.io/v1', $role->getApiVersion()); $this->assertEquals('admin', $role->getName()); + $this->assertEquals(['tier' => 'backend'], $role->getLabels()); $this->assertEquals([$rule], $role->getRules()); } @@ -63,6 +66,7 @@ public function runCreationTests() $role = $this->cluster->role() ->setName('admin') + ->setLabels(['tier' => 'backend']) ->addRules([$rule]); $this->assertFalse($role->isSynced()); @@ -77,6 +81,7 @@ public function runCreationTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $role->getApiVersion()); $this->assertEquals('admin', $role->getName()); + $this->assertEquals(['tier' => 'backend'], $role->getLabels()); $this->assertEquals([$rule], $role->getRules()); } @@ -109,6 +114,7 @@ public function runGetTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $role->getApiVersion()); $this->assertEquals('admin', $role->getName()); + $this->assertEquals(['tier' => 'backend'], $role->getLabels()); $this->assertEquals([$rule], $role->getRules()); } @@ -132,6 +138,7 @@ public function runUpdateTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $role->getApiVersion()); $this->assertEquals('admin', $role->getName()); + $this->assertEquals(['tier' => 'backend'], $role->getLabels()); $this->assertEquals([$rule], $role->getRules()); } diff --git a/tests/yaml/role.yaml b/tests/yaml/role.yaml index 9a86bb5b..0d0b929a 100644 --- a/tests/yaml/role.yaml +++ b/tests/yaml/role.yaml @@ -2,6 +2,8 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: admin + labels: + tier: backend rules: - apiGroups: [""] resources: From 77d8e0160ae6e6b63721e3e94a0d444084d5d80a Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Fri, 11 Dec 2020 10:18:08 +0100 Subject: [PATCH 13/16] Add labels to PersistentVolume --- src/Kinds/K8sPersistentVolume.php | 2 ++ tests/PersistentVolumeTest.php | 7 +++++++ tests/yaml/persistentvolume.yaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Kinds/K8sPersistentVolume.php b/src/Kinds/K8sPersistentVolume.php index 98c70fd8..a3e0e9c4 100644 --- a/src/Kinds/K8sPersistentVolume.php +++ b/src/Kinds/K8sPersistentVolume.php @@ -5,6 +5,7 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; use RenokiCo\PhpK8s\Traits\HasAccessModes; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasMountOptions; use RenokiCo\PhpK8s\Traits\HasSelector; use RenokiCo\PhpK8s\Traits\HasSpec; @@ -21,6 +22,7 @@ class K8sPersistentVolume extends K8sResource implements InteractsWithK8sCluster use HasStatus; use HasStatusPhase; use HasStorageClass; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/PersistentVolumeTest.php b/tests/PersistentVolumeTest.php index a430d5c7..626e828d 100644 --- a/tests/PersistentVolumeTest.php +++ b/tests/PersistentVolumeTest.php @@ -18,6 +18,7 @@ public function test_persistent_volume_build() $pv = $this->cluster->persistentVolume() ->setName('app') + ->setLabels(['tier' => 'backend']) ->setSource('awsElasticBlockStore', ['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx']) ->setCapacity(1, 'Gi') ->setAccessModes(['ReadWriteOnce']) @@ -26,6 +27,7 @@ public function test_persistent_volume_build() $this->assertEquals('v1', $pv->getApiVersion()); $this->assertEquals('app', $pv->getName()); + $this->assertEquals(['tier' => 'backend'], $pv->getLabels()); $this->assertEquals(['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx'], $pv->getSpec('awsElasticBlockStore')); $this->assertEquals('1Gi', $pv->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pv->getAccessModes()); @@ -39,6 +41,7 @@ public function test_persistent_volume_from_yaml() $this->assertEquals('v1', $pv->getApiVersion()); $this->assertEquals('app', $pv->getName()); + $this->assertEquals(['tier' => 'backend'], $pv->getLabels()); $this->assertEquals(['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx'], $pv->getSpec('awsElasticBlockStore')); $this->assertEquals('1Gi', $pv->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pv->getAccessModes()); @@ -67,6 +70,7 @@ public function runCreationTests() $pv = $this->cluster->persistentVolume() ->setName('app') + ->setLabels(['tier' => 'backend']) ->setSource('awsElasticBlockStore', ['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx']) ->setCapacity(1, 'Gi') ->setAccessModes(['ReadWriteOnce']) @@ -85,6 +89,7 @@ public function runCreationTests() $this->assertEquals('v1', $pv->getApiVersion()); $this->assertEquals('app', $pv->getName()); + $this->assertEquals(['tier' => 'backend'], $pv->getLabels()); $this->assertEquals(['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx'], $pv->getSpec('awsElasticBlockStore')); $this->assertEquals('1Gi', $pv->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pv->getAccessModes()); @@ -124,6 +129,7 @@ public function runGetTests() $this->assertEquals('v1', $pv->getApiVersion()); $this->assertEquals('app', $pv->getName()); + $this->assertEquals(['tier' => 'backend'], $pv->getLabels()); $this->assertEquals(['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx'], $pv->getSpec('awsElasticBlockStore')); $this->assertEquals('1Gi', $pv->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pv->getAccessModes()); @@ -145,6 +151,7 @@ public function runUpdateTests() $this->assertEquals('v1', $pv->getApiVersion()); $this->assertEquals('app', $pv->getName()); + $this->assertEquals(['tier' => 'backend'], $pv->getLabels()); $this->assertEquals(['fsType' => 'ext4', 'volumeID' => 'vol-xxxxx'], $pv->getSpec('awsElasticBlockStore')); $this->assertEquals('1Gi', $pv->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pv->getAccessModes()); diff --git a/tests/yaml/persistentvolume.yaml b/tests/yaml/persistentvolume.yaml index 15a6a861..524ac920 100644 --- a/tests/yaml/persistentvolume.yaml +++ b/tests/yaml/persistentvolume.yaml @@ -2,6 +2,8 @@ apiVersion: v1 kind: PersistentVolume metadata: name: app + labels: + tier: backend spec: awsElasticBlockStore: fsType: ext4 From 55cb0f44eaca03c310a257e275368214560dd4a9 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Fri, 11 Dec 2020 10:22:17 +0100 Subject: [PATCH 14/16] Add labels to PersistentVolumeClaim --- src/Kinds/K8sPersistentVolumeClaim.php | 2 ++ tests/PersistentVolumeClaimTest.php | 7 +++++++ tests/yaml/persistentvolumeclaim.yaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Kinds/K8sPersistentVolumeClaim.php b/src/Kinds/K8sPersistentVolumeClaim.php index 94025b6e..5aba6fa1 100644 --- a/src/Kinds/K8sPersistentVolumeClaim.php +++ b/src/Kinds/K8sPersistentVolumeClaim.php @@ -5,6 +5,7 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; use RenokiCo\PhpK8s\Traits\HasAccessModes; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasSelector; use RenokiCo\PhpK8s\Traits\HasSpec; use RenokiCo\PhpK8s\Traits\HasStatus; @@ -19,6 +20,7 @@ class K8sPersistentVolumeClaim extends K8sResource implements InteractsWithK8sCl use HasStatus; use HasStatusPhase; use HasStorageClass; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/PersistentVolumeClaimTest.php b/tests/PersistentVolumeClaimTest.php index ad7dd93d..f6177a5d 100644 --- a/tests/PersistentVolumeClaimTest.php +++ b/tests/PersistentVolumeClaimTest.php @@ -14,12 +14,14 @@ public function test_persistent_volume_claim_build() $pvc = $this->cluster->persistentVolumeClaim() ->setName('app-pvc') + ->setLabels(['tier' => 'backend']) ->setCapacity(1, 'Gi') ->setAccessModes(['ReadWriteOnce']) ->setStorageClass($standard); $this->assertEquals('v1', $pvc->getApiVersion()); $this->assertEquals('app-pvc', $pvc->getName()); + $this->assertEquals(['tier' => 'backend'], $pvc->getLabels()); $this->assertEquals('1Gi', $pvc->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pvc->getAccessModes()); $this->assertEquals('standard', $pvc->getStorageClass()); @@ -31,6 +33,7 @@ public function test_persistent_volume_claim_from_yaml() $this->assertEquals('v1', $pvc->getApiVersion()); $this->assertEquals('app-pvc', $pvc->getName()); + $this->assertEquals(['tier' => 'backend'], $pvc->getLabels()); $this->assertEquals('1Gi', $pvc->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pvc->getAccessModes()); $this->assertEquals('standard', $pvc->getStorageClass()); @@ -53,6 +56,7 @@ public function runCreationTests() $pvc = $this->cluster->persistentVolumeClaim() ->setName('app-pvc') + ->setLabels(['tier' => 'backend']) ->setCapacity(1, 'Gi') ->setAccessModes(['ReadWriteOnce']) ->setStorageClass($standard); @@ -69,6 +73,7 @@ public function runCreationTests() $this->assertEquals('v1', $pvc->getApiVersion()); $this->assertEquals('app-pvc', $pvc->getName()); + $this->assertEquals(['tier' => 'backend'], $pvc->getLabels()); $this->assertEquals('1Gi', $pvc->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pvc->getAccessModes()); $this->assertEquals('standard', $pvc->getStorageClass()); @@ -106,6 +111,7 @@ public function runGetTests() $this->assertEquals('v1', $pvc->getApiVersion()); $this->assertEquals('app-pvc', $pvc->getName()); + $this->assertEquals(['tier' => 'backend'], $pvc->getLabels()); $this->assertEquals('1Gi', $pvc->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pvc->getAccessModes()); $this->assertEquals('standard', $pvc->getStorageClass()); @@ -123,6 +129,7 @@ public function runUpdateTests() $this->assertEquals('v1', $pvc->getApiVersion()); $this->assertEquals('app-pvc', $pvc->getName()); + $this->assertEquals(['tier' => 'backend'], $pvc->getLabels()); $this->assertEquals('1Gi', $pvc->getCapacity()); $this->assertEquals(['ReadWriteOnce'], $pvc->getAccessModes()); $this->assertEquals('standard', $pvc->getStorageClass()); diff --git a/tests/yaml/persistentvolumeclaim.yaml b/tests/yaml/persistentvolumeclaim.yaml index 003ac612..92ef86e3 100644 --- a/tests/yaml/persistentvolumeclaim.yaml +++ b/tests/yaml/persistentvolumeclaim.yaml @@ -2,6 +2,8 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: name: app-pvc + labels: + tier: backend spec: resources: requests: From 8fd8145dfaf26d0d6a02c43a7399cb36fd8f789a Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Fri, 11 Dec 2020 10:31:52 +0100 Subject: [PATCH 15/16] Add labels to RoleBinding --- src/Kinds/K8sRoleBinding.php | 2 ++ tests/RoleBindingTest.php | 7 +++++++ tests/yaml/rolebinding.yaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Kinds/K8sRoleBinding.php b/src/Kinds/K8sRoleBinding.php index 0c2296a6..70b48c55 100644 --- a/src/Kinds/K8sRoleBinding.php +++ b/src/Kinds/K8sRoleBinding.php @@ -4,11 +4,13 @@ use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; use RenokiCo\PhpK8s\Contracts\Watchable; +use RenokiCo\PhpK8s\Traits\HasLabels; use RenokiCo\PhpK8s\Traits\HasSubjects; class K8sRoleBinding extends K8sResource implements InteractsWithK8sCluster, Watchable { use HasSubjects; + use HasLabels; /** * The resource Kind parameter. diff --git a/tests/RoleBindingTest.php b/tests/RoleBindingTest.php index 245555cd..f938800b 100644 --- a/tests/RoleBindingTest.php +++ b/tests/RoleBindingTest.php @@ -29,12 +29,14 @@ public function test_role_binding_build() $rb = $this->cluster->roleBinding() ->setName('user-binding') + ->setLabels(['tier' => 'backend']) ->setRole($role) ->addSubjects([$subject]) ->setSubjects([$subject]); $this->assertEquals('rbac.authorization.k8s.io/v1', $rb->getApiVersion()); $this->assertEquals('user-binding', $rb->getName()); + $this->assertEquals(['tier' => 'backend'], $rb->getLabels()); $this->assertEquals([$subject], $rb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'Role', 'name' => 'admin'], $rb->getRole()); } @@ -60,6 +62,7 @@ public function test_role_binding_from_yaml() $this->assertEquals('rbac.authorization.k8s.io/v1', $rb->getApiVersion()); $this->assertEquals('user-binding', $rb->getName()); + $this->assertEquals(['tier' => 'backend'], $rb->getLabels()); $this->assertEquals([$subject], $rb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'Role', 'name' => 'admin'], $rb->getRole()); } @@ -94,6 +97,7 @@ public function runCreationTests() $rb = $this->cluster->roleBinding() ->setName('user-binding') + ->setLabels(['tier' => 'backend']) ->setRole($role) ->addSubjects([$subject]) ->setSubjects([$subject]); @@ -111,6 +115,7 @@ public function runCreationTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $rb->getApiVersion()); $this->assertEquals('user-binding', $rb->getName()); + $this->assertEquals(['tier' => 'backend'], $rb->getLabels()); $this->assertEquals([$subject], $rb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'Role', 'name' => 'admin'], $rb->getRole()); } @@ -144,6 +149,7 @@ public function runGetTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $rb->getApiVersion()); $this->assertEquals('user-binding', $rb->getName()); + $this->assertEquals(['tier' => 'backend'], $rb->getLabels()); $this->assertEquals([$subject], $rb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'Role', 'name' => 'admin'], $rb->getRole()); } @@ -168,6 +174,7 @@ public function runUpdateTests() $this->assertEquals('rbac.authorization.k8s.io/v1', $rb->getApiVersion()); $this->assertEquals('user-binding', $rb->getName()); + $this->assertEquals(['tier' => 'backend'], $rb->getLabels()); $this->assertEquals([$subject], $rb->getSubjects()); $this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'Role', 'name' => 'admin'], $rb->getRole()); } diff --git a/tests/yaml/rolebinding.yaml b/tests/yaml/rolebinding.yaml index 749de96c..1c7cc228 100644 --- a/tests/yaml/rolebinding.yaml +++ b/tests/yaml/rolebinding.yaml @@ -2,6 +2,8 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: user-binding + labels: + tier: backend roleRef: apiGroup: rbac.authorization.k8s.io kind: Role From 48b2e3dc3c2983fd738b2ba93e81cbf53f0c5ea1 Mon Sep 17 00:00:00 2001 From: Mujib Azizi Date: Fri, 11 Dec 2020 15:42:51 +0100 Subject: [PATCH 16/16] Add documentation for Labels --- docs/kinds/Resource.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/kinds/Resource.md b/docs/kinds/Resource.md index 9ff2ec47..c264968c 100644 --- a/docs/kinds/Resource.md +++ b/docs/kinds/Resource.md @@ -58,6 +58,24 @@ $namespace->getName(); Alias for [setName($name)](#setnamename). It's just a naming convention for better filters on get. +## Labels + +### `setLabels(array $labels)` + +Set the labels of the resource. + +```php +$service->setLabels(['tier' => 'backend']); +``` + +### `getLabels()` + +Get the labels of a resource. + +```php +$service->getLabels(); +``` + ## API ### `getApiVersion()`