Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from coopnorge/init
Browse files Browse the repository at this point in the history
init cdk8s lib
  • Loading branch information
AtzeDeVries authored Aug 15, 2022
2 parents 6c16946 + a5f9048 commit 475bd65
Show file tree
Hide file tree
Showing 42 changed files with 68,004 additions and 27 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Output message
run: echo This is a default job to trigger output but it fails
- name: Fail when not in template
if: ${{ github.repository != 'coopnorge/github-template-default' }}
run: exit 1
run: echo Howdy
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/dist/**
33 changes: 10 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
# github-template-default
# Coop Norge cdk8s library

This is a basic template for when creating a Github repository.
> very much POC!
## Initialization instructions:

1. Setup [CODEOWNERS](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)
## Requirements

In a new branch Add you own team as the default code owner. Replace `*
@coopnorge/platform-guild` with `* @coopnorge/your-team-here`
`./CODEOWNERS`. Leave the rest of the file as is.
* cdk8s

```CODEOWNERS
* @coopnorge/your-team-here
/CODEOWNERS @coopnorge/security-guild
.github/workflows/security-* @coopnorge/security-guild
```
### Goal

Create a pull request, get it approved and merge it.
Make a library which can support many usecases

2. Setup and fix default [workflows](https://docs.github.com/en/actions/using-workflows)
#### Go Library

`.github/workflows/build.yaml` declares the default required GitHub Actions
job `build`. The job will fail on all builds in all repositories, except
<https://github.com/coopnorge/github-template-default>. Update the workflow
to do something that actually validates the content of your repository.
A library to build default kubernetes templates. A demo consumer can be found at [coopnorge/cdk8s-demo-consumer](https://github.com/coopnorge/cdk8s-demo-consumer)

3. Setup
[dependabot](https://playbook.internal.coop/platforms/cloud_platform/dev_build_deploy/github/guide_github_dependabot.html)
to update all dependencies from all ecosystems in the repository.
#### Yaml input

4. Create a new branch and start initializing your repository with the code you
need.
This library also has a binary which can render manifests based on yaml input. Its in the `cmd/cdk8slibrary` folder. Edit the test.yaml and do a `go run .` and it will render the manifest in the `dist` directory.
4 changes: 4 additions & 0 deletions cdk8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: go
app: go run .
imports:
- k8s
62 changes: 62 additions & 0 deletions cmd/cdk8slibrary/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//TODO: add ability to merge yamls
package main

import (
"log"
"os"

ck8slibrary "github.com/coopnorge/cdk8slibrary"
"github.com/creasty/defaults"
"github.com/mitchellh/mapstructure"
"gopkg.in/yaml.v2"

"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
"github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2"
)

type MyChartProps struct {
cdk8s.ChartProps
}

func NewMyChart(scope constructs.Construct, id string, props *ck8slibrary.ChartProps) cdk8s.Chart {
var cprops cdk8s.ChartProps

chart := cdk8s.NewChart(scope, jsii.String(id), &cprops)

ck8slibrary.Chart(chart, jsii.String("hello"), props)

return chart
}

func main() {
// Load the file; returns []byte
f, err := os.ReadFile("test.yaml")
if err != nil {
log.Fatal(err)
}
// Create an empty Car to be are target of unmarshalling
var c ck8slibrary.ChartProps
if err := defaults.Set(&c); err != nil {
panic(err)
}

var raw interface{}

// Unmarshal our input YAML file into empty interface
if err := yaml.Unmarshal(f, &raw); err != nil {
log.Fatal(err)
}

// Use mapstructure to convert our interface{} to Car (var c)
decoder, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{WeaklyTypedInput: true, Result: &c})
if err := decoder.Decode(raw); err != nil {
log.Fatal(err)
}

// Print out the new struct
//fmt.Printf("%+v\n", *c.Name)
app := cdk8s.NewApp(nil)
NewMyChart(app, "test", &c)
app.Synth()
}
10 changes: 10 additions & 0 deletions cmd/cdk8slibrary/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: kees
image: pan/piet
ports:
- port: 30
serviceEntries:
- name: google
hosts:
- google.nl
- google.no
- google.com
Loading

0 comments on commit 475bd65

Please sign in to comment.