Skip to content

Commit

Permalink
Add: ingress object
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbluf committed Oct 17, 2023
1 parent e914f32 commit e11ee2a
Show file tree
Hide file tree
Showing 9 changed files with 686 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DEFAULT=help

MODULE=deploy

.PHONY: help test build push tools
.PHONY: help test build push tools fmt

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
Expand All @@ -21,6 +21,7 @@ get: ## Update Kubernetes API CUE definitions
@cue get go k8s.io/api/core/v1
@cue get go k8s.io/api/apps/v1
@cue get go k8s.io/api/rbac/v1
@cue get go k8s.io/api/networking/v1
@cue get go k8s.io/apimachinery/pkg/apis/meta/v1
@cue get go k8s.io/apimachinery/pkg/runtime
@cue get go k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
Expand All @@ -42,6 +43,10 @@ build: ## Build with timoni with ns+name provided as arg/flag
@timoni build -n testing test .


fmt: ## Format cue files
@cue fmt .
@cue fmt ./templates

e2e: ## Run full flow + ep validate
@$(MAKE) apply
@test/validate.sh
Expand Down
7 changes: 7 additions & 0 deletions cue.mod/gen/k8s.io/api/networking/v1/register_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go k8s.io/api/networking/v1

package v1

#GroupName: "networking.k8s.io"
588 changes: 588 additions & 0 deletions cue.mod/gen/k8s.io/api/networking/v1/types_go_gen.cue

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go k8s.io/api/networking/v1

package v1

// AnnotationIsDefaultIngressClass can be used to indicate that an
// IngressClass should be considered default. When a single IngressClass
// resource has this annotation set to true, new Ingress resources without a
// class specified will be assigned this default class.
#AnnotationIsDefaultIngressClass: "ingressclass.kubernetes.io/is-default-class"
22 changes: 18 additions & 4 deletions templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Containers
// main
image: timoniv1.#Image
image: timoniv1.#Image
imagePullPolicy: *"IfNotPresent" | string
livenessProbe?: corev1.#Probe
readinessProbe?: corev1.#Probe
Expand All @@ -44,12 +44,21 @@ import (

// Service
service: {
port: *80 | int & >0 & <=65535
port: *80 | int & >0 & <=65535
protocol: *"TCP" | string
}

configMap: {
ingress: {
create: *false | bool
host: *"" | string
http: [{
path: *"/" | string
port: *80 | int & >0 & <=65535
}]
}

configMap: {
create: *false | bool
immutable: *true | bool
// data: *{}
}
Expand All @@ -62,8 +71,13 @@ import (
objects: {
sa: #ServiceAccount & {_config: config}
svc: #Service & {_config: config}

if config.ingress.create {
ing: #Ingress & {_config: config}
}

if config.configMap.create {
cm: #ConfigMap & {_config: config}
cm: #ConfigMap & {_config: config}
}
deploy: #Deployment & {
_config: config
Expand Down
6 changes: 3 additions & 3 deletions templates/deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
serviceAccountName: _config.metadata.name
containers: [
{
name: _config.metadata.name
image: "\(_config.image.repository):\(_config.image.tag)"
name: _config.metadata.name
image: "\(_config.image.repository):\(_config.image.tag)"
imagePullPolicy: _config.imagePullPolicy
ports: [
if _config.ports != _|_ {
Expand Down Expand Up @@ -68,7 +68,7 @@ import (
for container in _config.sidecarContainers {
container
}
}
},
]
if _config.volumes != _|_ {
volumes: _config.Volumes
Expand Down
39 changes: 39 additions & 0 deletions templates/ingress.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package templates

import (
netv1 "k8s.io/api/networking/v1"
)

#Ingress: netv1.#Ingress & {
_config: #Config
apiVersion: "networking.k8s.io/v1"
kind: "Ingress"
metadata: {
name: _config.metadata.name
namespace: _config.metadata.namespace
labels: _config.metadata.labels
if _config.metadata.annotations != _|_ {
annotations: _config.metadata.annotations
}
}
spec: {
rules: [{
if _config.ingress.host != "" {
host: _config.ingress.host
}
http: {
paths: [
for setup in _config.ingress.http {
path: setup.path
backend: {
service: {
name: _config.metadata.name
port: number: setup.port
}
}
},
]
}
}]
}
}
13 changes: 7 additions & 6 deletions test_values.cue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ values: {
port: "http"
}
}
// sidecarContainers: [
// {
// name: "main"
// image: "cgr.dev/chainguard/nginx:1.25.1"
// },
// ]
ingress: {
create: true
http: [{
path: "/test"
port: 80
}]
}
}
7 changes: 7 additions & 0 deletions values.cue
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ values: {
digest: "sha256:d2b0e52d7c2e5dd9fe5266b163e14d41ed97fd380deb55a36ff17efd145549cd"
tag: "1.25.1"
}
ingress: {
create: false
http: [{
path: "/"
port: 80
}]
}
}

0 comments on commit e11ee2a

Please sign in to comment.