From 7b327b38e7546be1a6ad3e50af92e13fb1ce14d5 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Fri, 3 Nov 2023 14:22:22 +0100 Subject: [PATCH] WIP: something --- example/db-operator/package.yaml | 5 +++ example/db-operator/workload/workload.yaml | 20 +++++++++++ go.mod | 11 ++++++ go.sum | 10 ++++++ internal/controller/controller.go | 9 +++++ internal/templater/templater.go | 9 +++++ internal/templater/templater_test.go | 1 + pkg/types/image/image.go | 6 ++++ pkg/types/pkgdef/pkfdef.go | 14 ++++++++ pkg/types/workload/workload.go | 18 ++++++++++ pkg/types/workload/workload_test.go | 40 ++++++++++++++++++++++ 11 files changed, 143 insertions(+) create mode 100644 example/db-operator/package.yaml create mode 100644 example/db-operator/workload/workload.yaml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/controller/controller.go create mode 100644 internal/templater/templater.go create mode 100644 internal/templater/templater_test.go create mode 100644 pkg/types/image/image.go create mode 100644 pkg/types/pkgdef/pkfdef.go create mode 100644 pkg/types/workload/workload.go create mode 100644 pkg/types/workload/workload_test.go diff --git a/example/db-operator/package.yaml b/example/db-operator/package.yaml new file mode 100644 index 0000000..293acb5 --- /dev/null +++ b/example/db-operator/package.yaml @@ -0,0 +1,5 @@ +name: db-operator +version: 1.0.0 +image: + tag: 1.15.3 + repository: db-operator diff --git a/example/db-operator/workload/workload.yaml b/example/db-operator/workload/workload.yaml new file mode 100644 index 0000000..21ccf47 --- /dev/null +++ b/example/db-operator/workload/workload.yaml @@ -0,0 +1,20 @@ +workload: + kind: Deployment + replicas: 1 + containers: + - name: controller + image: {{ .Image }} + imagePullPolicy: Always + commands: + - sh + args: + - -c + - 'sleep 1000' + - name: ubuntu + image: ubuntu:latest + imagePullPolicy: Always + commands: + - sh + args: + - -c + - 'sleep 1000' diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6179ffb --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module git.badhouseplants.net/allanger/shoebill + +go 1.21.3 + +require github.com/stretchr/testify v1.8.4 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fa4b6e6 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/controller/controller.go b/internal/controller/controller.go new file mode 100644 index 0000000..c1d925d --- /dev/null +++ b/internal/controller/controller.go @@ -0,0 +1,9 @@ +package controller + +type Client struct {} + +func (cli *Client) Install () error { + // Generate the package from templates + + return nil +} diff --git a/internal/templater/templater.go b/internal/templater/templater.go new file mode 100644 index 0000000..98132a2 --- /dev/null +++ b/internal/templater/templater.go @@ -0,0 +1,9 @@ +package templater + +// Datasource for template rendering +type TemplateDS struct { +} + +func (tds *TemplateDS) Render() { + +} diff --git a/internal/templater/templater_test.go b/internal/templater/templater_test.go new file mode 100644 index 0000000..b136d9b --- /dev/null +++ b/internal/templater/templater_test.go @@ -0,0 +1 @@ +package templater_test diff --git a/pkg/types/image/image.go b/pkg/types/image/image.go new file mode 100644 index 0000000..df7c716 --- /dev/null +++ b/pkg/types/image/image.go @@ -0,0 +1,6 @@ +package image + +type Image struct { + Repository string + Tag string +} diff --git a/pkg/types/pkgdef/pkfdef.go b/pkg/types/pkgdef/pkfdef.go new file mode 100644 index 0000000..42a8e79 --- /dev/null +++ b/pkg/types/pkgdef/pkfdef.go @@ -0,0 +1,14 @@ +package pkgdef + + +type Package struct { + Name string + Version string + AppVersion string + Image *Image +} + +type Image struct { + Repository string + Tag string +} diff --git a/pkg/types/workload/workload.go b/pkg/types/workload/workload.go new file mode 100644 index 0000000..461d573 --- /dev/null +++ b/pkg/types/workload/workload.go @@ -0,0 +1,18 @@ +package workload + +import ( + "fmt" +) + +type Workload struct { + Kind string + Replicas int +} + +func (wd *Workload) ValidateKind() error { + if wd.Kind == "Deployment" || wd.Kind == "StatefulSet" || wd.Kind == "DaemonSet" { + return nil + } + err := fmt.Errorf("kind is not valid, expect Deployment|StatefulSet|DaemonSet, got %s", wd.Kind) + return err +} diff --git a/pkg/types/workload/workload_test.go b/pkg/types/workload/workload_test.go new file mode 100644 index 0000000..3be7b6f --- /dev/null +++ b/pkg/types/workload/workload_test.go @@ -0,0 +1,40 @@ +package workload_test + +import ( + "testing" + + "git.badhouseplants.net/allanger/shoebill/pkg/types/workload" + "github.com/stretchr/testify/assert" +) + +func TestUnitKindValidatorDeployment(t *testing.T) { + wd := &workload.Workload{ + Kind: "Deployment", + } + err := wd.ValidateKind() + assert.NoError(t, err) +} + +func TestUnitKindValidatorStatefulSet(t *testing.T) { + wd := &workload.Workload{ + Kind: "StatefulSet", + } + err := wd.ValidateKind() + assert.NoError(t, err) +} + +func TestUnitKindValidatorDeamonSet(t *testing.T) { + wd := &workload.Workload{ + Kind: "DaemonSet", + } + err := wd.ValidateKind() + assert.NoError(t, err) +} + +func TestUnitKindValidatorInvalid(t *testing.T) { + wd := &workload.Workload{ + Kind: "Invalid", + } + err := wd.ValidateKind() + assert.ErrorContains(t, err, "got Invalid") +}