-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
😐 Make cluster components more generic (#157)
Lay out components more intuitively. Add a generic Component type to handle cluster components more elegantly.
- Loading branch information
1 parent
531b2c6
commit 236afe9
Showing
7 changed files
with
255 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.