Skip to content

Commit

Permalink
Merge pull request #70 from svenvanhees/master
Browse files Browse the repository at this point in the history
Support ingress tls configuration
  • Loading branch information
rennokki authored Feb 20, 2021
2 parents e0db4eb + a462e7c commit cc0c550
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/kinds/Ingress.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ $ingress = $cluster->ingress()
->setName('nginx')
->setLabels(['tier' => 'backend'])
->setSelectors(['app' => 'frontend'])
->setTls([[
'hosts' => [
'test.com'
],
'secretName'=> 'verySecretName'
]])
->setRules([[
'host' => 'nginx.test.com',
'http' => [
Expand Down
21 changes: 21 additions & 0 deletions src/Kinds/K8sIngress.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,25 @@ public function getRules(): array
{
return $this->getSpec('rules', []);
}

/**
* Set the spec tls.
*
* @param array $rules
* @return $this
*/
public function setTls(array $tlsData = [])
{
return $this->setSpec('tls', $tlsData);
}

/**
* Get the tls spec.
*
* @return array
*/
public function getTls(): array
{
return $this->getSpec('tls', []);
}
}
17 changes: 17 additions & 0 deletions tests/IngressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,33 @@ class IngressTest extends TestCase
],
]];

/**
* The default testing tls.
*
* @var array
*/
protected static $tls = [[
'hosts' => [
'nginx.test.com',
],
'secretName' => 'verySecretName',
]];

public function test_ingress_build()
{
$ing = $this->cluster->ingress()
->setName('nginx')
->setLabels(['tier' => 'backend'])
->setAnnotations(['nginx/ann' => 'yes'])
->setTls(self::$tls)
->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::$tls, $ing->getTls());
$this->assertEquals(self::$rules, $ing->getRules());
}

Expand Down Expand Up @@ -71,6 +85,7 @@ public function runCreationTests()
->setName('nginx')
->setLabels(['tier' => 'backend'])
->setAnnotations(['nginx/ann' => 'yes'])
->setTls(self::$tls)
->setRules(self::$rules);

$this->assertFalse($ing->isSynced());
Expand All @@ -87,6 +102,7 @@ public function runCreationTests()
$this->assertEquals('nginx', $ing->getName());
$this->assertEquals(['tier' => 'backend'], $ing->getLabels());
$this->assertEquals(['nginx/ann' => 'yes'], $ing->getAnnotations());
$this->assertEquals(self::$tls, $ing->getTls());
$this->assertEquals(self::$rules, $ing->getRules());
}

Expand Down Expand Up @@ -134,6 +150,7 @@ public function runUpdateTests()
$this->assertEquals('nginx', $ing->getName());
$this->assertEquals(['tier' => 'backend'], $ing->getLabels());
$this->assertEquals([], $ing->getAnnotations());
$this->assertEquals(self::$tls, $ing->getTls());
$this->assertEquals(self::$rules, $ing->getRules());
}

Expand Down

0 comments on commit cc0c550

Please sign in to comment.