Skip to content

Commit

Permalink
😐 Make cluster components more generic (#157)
Browse files Browse the repository at this point in the history
Lay out components more intuitively. Add a generic Component type to
handle cluster components more elegantly.
  • Loading branch information
aaronmondal authored Jun 2, 2023
1 parent 531b2c6 commit 236afe9
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 135 deletions.
13 changes: 9 additions & 4 deletions devtools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
load("@rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "deployments",
srcs = ["deployments/deployments.go"],
importpath = "github.com/eomii/rules_ll/devtools/deployments",
name = "components",
srcs = [
"components/cilium.go",
"components/components.go",
"components/tekton.go",
"components/zot.go",
],
importpath = "github.com/eomii/rules_ll/devtools/components",
deps = [
"@com_github_pulumi_pulumi_kubernetes_sdk_v3//go/kubernetes/helm/v3:helm",
"@com_github_pulumi_pulumi_kubernetes_sdk_v3//go/kubernetes/yaml",
Expand All @@ -27,7 +32,7 @@ go_binary(
visibility = ["//visibility:public"],
deps = [
":clusters",
":deployments",
":components",
"@com_github_pulumi_pulumi_sdk_v3//go/auto",
"@com_github_pulumi_pulumi_sdk_v3//go/auto/optup",
"@com_github_pulumi_pulumi_sdk_v3//go/common/tokens",
Expand Down
76 changes: 76 additions & 0 deletions devtools/components/cilium.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package components

import (
"fmt"

"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type Cilium struct {
Version string
}

//nolint:nolintlint,typecheck // The helm type is broken.
func (component *Cilium) Install(
ctx *pulumi.Context,
name string,
) ([]pulumi.Resource, error) {
cilium, err := helm.NewChart(ctx, name, helm.ChartArgs{
Chart: pulumi.String("cilium"),
Version: pulumi.String(component.Version),
Namespace: pulumi.String("kube-system"),
FetchArgs: helm.FetchArgs{
Repo: pulumi.String("https://helm.cilium.io/"),
},
Values: pulumi.Map{
// Name of the `control-plane` node in `kubectl get nodes`.
"k8sServiceHost": pulumi.String("kind-control-plane"),

// Forwarded port in `docker ps` for the control plane.
"k8sServicePort": pulumi.String("6443"),

// Required for proper Cilium operation.
"kubeProxyReplacement": pulumi.String("strict"),

// IPAM config subnets from `docker network inspect kind`.
"ipv4NativeRoutingCIDR": pulumi.String("172.20.0.0/16"),
"ipv6NativeRoutingCIDR": pulumi.String("fc00:f853:ccd:e793::/64"),

// Faster masquerading.
"bpf": pulumi.Map{
"masquerade": pulumi.Bool(true),
"tproxy": pulumi.Bool(true),
},

"ipam": pulumi.Map{
"mode": pulumi.String("kubernetes"),
"operator": pulumi.Map{
// Default values for kind.
"clusterPoolIPv4PodCIDRList": pulumi.String(
"10.244.0.0/16",
),
"clusterPoolIPv6PodCIDRList": pulumi.String(
"fd00:10:244::/56",
),
},
},

"image": pulumi.Map{"pullPolicy": pulumi.String("IfNotPresent")},

"hubble": pulumi.Map{
"relay": pulumi.Map{"enabled": pulumi.Bool(true)},
"ui": pulumi.Map{"enabled": pulumi.Bool(true)},
},

// This causes issues. Find out why and enable it.
// "autoDirectNodeRoutes": pulumi.Bool(true),
// "tunnel": pulumi.String("disabled"),
},
})
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

return []pulumi.Resource{cilium}, nil
}
39 changes: 39 additions & 0 deletions devtools/components/components.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package components

import (
"errors"
"fmt"
"log"
"os"

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

var (
errPulumi = errors.New("pulumi error")
errComponent = errors.New("component error")
)

func Check(_ []pulumi.Resource, err error) {
if err != nil {
log.Println(err)
os.Exit(1)
}
}

type Component interface {
Install(ctx *pulumi.Context, name string) ([]pulumi.Resource, error)
}

func AddComponent[C Component](
ctx *pulumi.Context,
name string,
component C,
) ([]pulumi.Resource, error) {
resources, err := component.Install(ctx, name)
if err != nil {
return nil, fmt.Errorf("%w: %w", errComponent, err)
}

return resources, nil
}
71 changes: 71 additions & 0 deletions devtools/components/tekton.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package components

import (
"fmt"

"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type TektonPipelines struct {
Version string
}

func (component *TektonPipelines) Install(
ctx *pulumi.Context,
name string,
) ([]pulumi.Resource, error) {
tektonPipelines, err := yaml.NewConfigFile(ctx, name, &yaml.ConfigFileArgs{
File: fmt.Sprintf(
"https://storage.googleapis.com/tekton-releases/pipeline/previous/v%s/release.yaml",
component.Version,
),
})
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

return []pulumi.Resource{tektonPipelines}, nil
}

type TektonTriggers struct {
Version string
}

func (component *TektonTriggers) Install(
ctx *pulumi.Context,
name string,
) ([]pulumi.Resource, error) {
tektonTriggers, err := yaml.NewConfigFile(ctx, name, &yaml.ConfigFileArgs{
File: fmt.Sprintf(
"https://storage.googleapis.com/tekton-releases/pipeline/triggers/previous/v%s/release.yaml",
component.Version,
),
})
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

return []pulumi.Resource{tektonTriggers}, nil
}

type TektonDashboard struct {
Version string
}

func (component *TektonDashboard) Install(
ctx *pulumi.Context,
name string,
) ([]pulumi.Resource, error) {
tektonDashboard, err := yaml.NewConfigFile(ctx, name, &yaml.ConfigFileArgs{
File: fmt.Sprintf(
"https://storage.googleapis.com/tekton-releases/dashboard/previous/v%s/release.yaml",
component.Version,
),
})
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

return []pulumi.Resource{tektonDashboard}, nil
}
34 changes: 34 additions & 0 deletions devtools/components/zot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package components

import (
"fmt"

"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type Zot struct {
Version string
}

//
//nolint:nolintlint,typecheck // The helm type is broken.
func (component *Zot) Install(
ctx *pulumi.Context,
name string,
) ([]pulumi.Resource, error) {
zot, err := helm.NewChart(ctx, name, helm.ChartArgs{
Chart: pulumi.String("zot"),
Version: pulumi.String(component.Version),
Namespace: pulumi.String("kube-system"),
FetchArgs: helm.FetchArgs{
Repo: pulumi.String("https://zotregistry.io/helm-charts"),
},
},
)
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

return []pulumi.Resource{zot}, nil
}
125 changes: 0 additions & 125 deletions devtools/deployments/deployments.go

This file was deleted.

Loading

0 comments on commit 236afe9

Please sign in to comment.