Skip to content
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
14 changes: 10 additions & 4 deletions getdeck/sources/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from getdeck.fetch.types import DeckfileAux, SourceAux

from getdeck.sources.generator import RenderBehavior
from getdeck.sources.generator import RenderBehavior, RenderError
from getdeck.sources.types import K8sSourceFile

logger = logging.getLogger("deck")
Expand All @@ -11,12 +11,18 @@
class Inline(RenderBehavior):
def render(self, deckfile_aux: DeckfileAux, source_aux: SourceAux, **kwargs):
try:
# optional arguments
arguments = {}
if self.namespace:
arguments["namespace"] = self.namespace

source_file = K8sSourceFile(
name="Deckfile",
content=source_aux.source.content,
namespace=self.namespace,
**arguments,
)
return [source_file]
except Exception as e:
logger.error(f"Error processing file: {e}")
raise e
logger.error(f"Processing inline source failed: {deckfile_aux.location}")
logger.debug(e)
raise RenderError(str(e))
File renamed without changes.
40 changes: 40 additions & 0 deletions test/sources/deck.empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "1"

cluster:
provider: k3d
minVersion: 4.0.0
name: test-empty-file
nativeConfig:
apiVersion: k3d.io/v1alpha4
kind: Simple
servers: 1
agents: 1
image: rancher/k3s:v1.22.9-k3s1
options:
k3s:
extraArgs:
- arg: --disable=traefik
nodeFilters:
- server:*
ports:
- port: 61346:80
nodeFilters:
- loadbalancer
- port: 8443:443
nodeFilters:
- loadbalancer
- port: 31820:31820/UDP
nodeFilters:
- agent:0

decks:
- name: empty
namespace: default
sources:
- type: inline
content:
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": { "name": "content", "labels": { "name": "content" } },
}
25 changes: 2 additions & 23 deletions test/sources/deck.file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "1"
cluster:
provider: k3d
minVersion: 4.0.0
name: test-sources-file
name: test-file-sources
nativeConfig:
apiVersion: k3d.io/v1alpha4
kind: Simple
Expand All @@ -28,22 +28,9 @@ cluster:
- agent:0

decks:
- name: hello
- name: test
namespace: default
sources:
- type: helm
ref: https://kubernetes.github.io/ingress-nginx
chart: ingress-nginx
releaseName: ingress-nginx
namespace: ingress-nginx
helmArgs:
- --create-namespace
parameters:
- name: controller.admissionWebhooks.enabled
value: false
- name: controller.ingressClassResource.default
value: true

- type: file
ref: ./hello.yaml

Expand All @@ -60,11 +47,3 @@ decks:
ref: git@github.com:Getdeck/getdeck.git
targetRevision: main
path: test/beiboot/hello.yaml

- type: inline
content:
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": { "name": "content", "labels": { "name": "content" } },
}
45 changes: 45 additions & 0 deletions test/sources/deck.helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: "1"

cluster:
provider: k3d
minVersion: 4.0.0
name: test-helm-sources
nativeConfig:
apiVersion: k3d.io/v1alpha4
kind: Simple
servers: 1
agents: 1
image: rancher/k3s:v1.22.9-k3s1
options:
k3s:
extraArgs:
- arg: --disable=traefik
nodeFilters:
- server:*
ports:
- port: 61346:80
nodeFilters:
- loadbalancer
- port: 8443:443
nodeFilters:
- loadbalancer
- port: 31820:31820/UDP
nodeFilters:
- agent:0

decks:
- name: test
namespace: default
sources:
- type: helm
ref: https://kubernetes.github.io/ingress-nginx
chart: ingress-nginx
releaseName: ingress-nginx
namespace: ingress-nginx
helmArgs:
- --create-namespace
parameters:
- name: controller.admissionWebhooks.enabled
value: false
- name: controller.ingressClassResource.default
value: true
49 changes: 49 additions & 0 deletions test/sources/deck.inline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "1"

cluster:
provider: k3d
minVersion: 4.0.0
name: test-inline-sources
nativeConfig:
apiVersion: k3d.io/v1alpha4
kind: Simple
servers: 1
agents: 1
image: rancher/k3s:v1.22.9-k3s1
options:
k3s:
extraArgs:
- arg: --disable=traefik
nodeFilters:
- server:*
ports:
- port: 61346:80
nodeFilters:
- loadbalancer
- port: 8443:443
nodeFilters:
- loadbalancer
- port: 31820:31820/UDP
nodeFilters:
- agent:0

decks:
- name: test
namespace: default
sources:
- type: inline
content:
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": { "name": "content", "labels": { "name": "content" } },
}

- type: inline
content:
kind: Namespace
apiVersion: v1
metadata:
- name: content
- labels:
- name: content
23 changes: 22 additions & 1 deletion test/src/fetch/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@


class FetchDataTest(TestCase):
def test_local(self):
def test_local_empty(self):
location = "./test/deckfile/deck.empty.yaml"
data_aux = fetch_data(location)
self.assertIsNotNone(data_aux.deckfile)
self.assertIsNotNone(data_aux.deckfile_aux)
self.assertEqual(len(data_aux.source_auxs), 1)

def test_local_inline(self):
location = "./test/sources/deck.inline.yaml"
data_aux = fetch_data(location)
self.assertIsNotNone(data_aux.deckfile)
self.assertIsNotNone(data_aux.deckfile_aux)
self.assertEqual(len(data_aux.source_auxs), 2)

def test_local_file(self):
location = "./test/sources/deck.file.yaml"
data_aux = fetch_data(location)
self.assertIsNotNone(data_aux.deckfile)
self.assertIsNotNone(data_aux.deckfile_aux)
self.assertEqual(len(data_aux.source_auxs), 5)

def test_local_helm(self):
location = "./test/sources/deck.helm.yaml"
data_aux = fetch_data(location)
self.assertIsNotNone(data_aux.deckfile)
self.assertIsNotNone(data_aux.deckfile_aux)
self.assertEqual(len(data_aux.source_auxs), 1)

def test_git_with_no_deckfile(self):
location = "git@github.com:Getdeck/getdeck.git"
with self.assertRaises(RuntimeError):
Expand Down
2 changes: 1 addition & 1 deletion test/src/fetch/test_source_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_none_helm_source(self):


class SourceFetcherTest(TestCase):
def test_inline(self):
def test_file(self):
location = "https://raw.githubusercontent.com/Getdeck/getdeck/main/test/sources/resources/hello.yaml"
source = DeckfileFileSource(ref=location)
source_aux = SourceAux(location=location)
Expand Down
34 changes: 34 additions & 0 deletions test/src/sources/test_render_behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from unittest import TestCase
from getdeck.deckfile.file import DeckfileInlineSource
from getdeck.fetch.types import DeckfileAux, SourceAux
from getdeck.sources.inline import Inline
import itertools


class InlineTest(TestCase):
def test_render(self):
test_namespaces = [None, "default", "test"]
test_contents = [{}]
combinations = itertools.product(test_namespaces, test_contents)

for combination in combinations:
namespace = combination[0]
content = combination[1]

deckfile_aux = DeckfileAux(location="test")
source_aux = SourceAux(source=DeckfileInlineSource(content=content))

render_behavior = Inline(
path=None,
source=None,
config=None,
namespace=namespace,
)
source_files = render_behavior.render(
deckfile_aux=deckfile_aux, source_aux=source_aux
)

self.assertEqual(len(source_files), 1)
source_file = source_files[0]
self.assertEqual(source_file.namespace, namespace or "default")
self.assertEqual(source_file.content, content)