Skip to content

Commit

Permalink
Add tekton operator to local dev cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
SchahinRohani committed Sep 8, 2024
1 parent 0ab5a99 commit c2ebd7b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 152 deletions.
9 changes: 6 additions & 3 deletions native-cli/components/embedded/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
resources:
- capacitor.yaml
# Tasks
- nix2container-copyto.yaml
- rebuild-nativelink.yaml
- skopeo-copy.yaml
- cosign-verify.yaml
- skopeo-check-hashlocked-url.yaml
- nix2container-image-info.yaml
- trigger.yaml
- update-image-tags.yaml
- capacitor.yaml
# Pipelines
- rebuild-nativelink.yaml
# Triggers
- trigger.yaml
# - nativelink-gateways.yaml # Gateways are handled in Pulumi via the
# NativeLinkGateways resource.
9 changes: 7 additions & 2 deletions native-cli/components/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

// The configuration for Flux.
type Flux struct {
Version string
Version string
Dependencies []pulumi.Resource
}

// Install sets up Flux in the cluster.
Expand All @@ -22,7 +23,11 @@ func (component *Flux) Install(
"https://github.com/fluxcd/flux2/releases/download/v%s/install.yaml",
component.Version,
),
})
},
pulumi.DependsOn(
component.Dependencies,
),
)
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}
Expand Down
157 changes: 44 additions & 113 deletions native-cli/components/tekton.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,141 +2,72 @@ package components

import (
"fmt"
"time"

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

// The configuration for Tekton Pipelines.
type TektonPipelines struct {
Version string
}

// Install installs Tekton Pipelines on the cluster.
//
// This function performs an additional feature-flag transformation to set
// `disable-affinity-assistant=true` and `coscheduling=pipelineruns`.
func (component *TektonPipelines) Install(
ctx *pulumi.Context,
name string,
) ([]pulumi.Resource, error) {
// This transformation disables the affinity assistant switches coscheduling
// from "workspace" to "pipelineruns". This allows us to use multiple PVCs
// in the same task. Usually this is discouraged for storage locality
// reasons, but since we're running on a local kind cluster that doesn't
// matter to us.
transformation := func(state map[string]interface{}, _ ...pulumi.ResourceOption) {
if kind, kindExists := state["kind"].(string); kindExists &&
kind == "ConfigMap" {
metadata, metadataExists := state["metadata"].(map[string]interface{})
if !metadataExists {
return
}

name, nameExists := metadata["name"].(string)

namespace, namespaceExists := metadata["namespace"].(string)

if nameExists && namespaceExists && name == "feature-flags" &&
namespace == "tekton-pipelines" {
data, dataExists := state["data"].(map[string]interface{})
if dataExists {
data["disable-affinity-assistant"] = "true" // Your specific configuration change
data["coschedule"] = "pipelineruns"
}
}
}
}

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,
),
Transformations: []yaml.Transformation{transformation},
})
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

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

// The configuration for Tekton Triggers.
type TektonTriggers struct {
type TektonOperator struct {
Version string
Dependencies []pulumi.Resource
}

// Install installs the Tekton Triggers release and interceptors on the cluster.
func (component *TektonTriggers) Install(
// Install installs Tekton Operator on the cluster and applies the TektonConfig.
func (component *TektonOperator) 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/triggers/previous/v%s/release.yaml",
// URL for TektonConfig
urlBase := "https://raw.githubusercontent.com/tektoncd/operator/"
urlPath := "/config/crs/kubernetes/config/all/operator_v1alpha1_config_cr.yaml"

// Install Tekton Operator with transformations
tektonOperator, err := yaml.NewConfigGroup(ctx, name, &yaml.ConfigGroupArgs{
Files: []string{
fmt.Sprintf(
"https://storage.googleapis.com/tekton-releases/operator/previous/v%s/release.yaml",
component.Version,
),
},
pulumi.DependsOn(
component.Dependencies,
),
)
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}

tektonTriggersInterceptors, err := yaml.NewConfigFile(
ctx,
name+"-interceptors",
&yaml.ConfigFileArgs{
File: fmt.Sprintf(
"https://storage.googleapis.com/tekton-releases/triggers/previous/v%s/interceptors.yaml",
fmt.Sprintf(
urlBase+"v%s"+urlPath,
component.Version,
),
},
pulumi.DependsOn(
[]pulumi.Resource{tektonTriggers},
),
)
Transformations: []yaml.Transformation{
func(state map[string]interface{}, _ ...pulumi.ResourceOption) {
if kind, kindExists := state["kind"].(string); kindExists &&
kind == "TektonConfig" {
spec, specExists := state["spec"].(map[string]interface{})
if !specExists {
return
}
pipeline, pipelineExists := spec["pipeline"].(map[string]interface{})
if !pipelineExists {
pipeline = map[string]interface{}{}
spec["pipeline"] = pipeline
}
pipeline["disable-affinity-assistant"] = true
pipeline["coschedule"] = "pipelineruns"
}
},
},
}, pulumi.DependsOn(component.Dependencies))
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
return nil, fmt.Errorf("failed to install Tekton Operator: %w", err)
}

return []pulumi.Resource{tektonTriggers, tektonTriggersInterceptors}, nil
}
ready := waitForTektonToBeReady()
if !ready {
return nil, fmt.Errorf("tekton webhook is not ready: %w", err)
}

// Configuration for the Tekton Dashboard.
type TektonDashboard struct {
Version string
Dependencies []pulumi.Resource
return []pulumi.Resource{tektonOperator}, nil
}

// Install installs the Tekton Dashboard on the cluster.
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,
),
},
pulumi.DependsOn(
component.Dependencies,
),
)
if err != nil {
return nil, fmt.Errorf("%w: %w", errPulumi, err)
}
func waitForTektonToBeReady() bool {
// Simulate Tekton State Gathering
time.Sleep(60 * time.Second) //nolint:mnd

return []pulumi.Resource{tektonDashboard}, nil
return true
}
53 changes: 19 additions & 34 deletions native-cli/programs/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,28 @@ func ProgramForLocalCluster(ctx *pulumi.Context) error {
os.Exit(1)
}

flux, err := components.AddComponent(
tektonOperator, err := components.AddComponent(
ctx,
"flux",
&components.Flux{Version: "2.3.0"},
)
if err != nil {
log.Println(err)
os.Exit(1)
}

tektonPipelines, err := components.AddComponent(
ctx,
"tekton-pipelines",
&components.TektonPipelines{
Version: "0.58.0",
"tekton-operator",
&components.TektonOperator{
Version: "0.72.0",
Dependencies: slices.Concat(
cilium,
),
},
)
if err != nil {
log.Println(err)
os.Exit(1)
}

tektonTriggers, err := components.AddComponent(
flux, err := components.AddComponent(
ctx,
"tekton-triggers",
&components.TektonTriggers{
Version: "0.26.1",
"flux",
&components.Flux{
Version: "2.3.0",
Dependencies: slices.Concat(
tektonPipelines,
cilium,
),
},
)
Expand All @@ -95,37 +88,29 @@ func ProgramForLocalCluster(ctx *pulumi.Context) error {
os.Exit(1)
}

components.Check(components.AddComponent(
ctx,
"tekton-dashboard",
&components.TektonDashboard{
Version: "0.45.0",
Dependencies: slices.Concat(
tektonPipelines, tektonTriggers,
),
},
))

components.Check(components.AddComponent(
ctx,
"rebuild-nativelink",
&components.RebuildNativeLink{
Dependencies: slices.Concat(
cilium,
tektonPipelines,
tektonTriggers,
localSources,
nixStore,
flux,
tektonOperator,
),
},
))

nativeLinkGateways, err := components.AddComponent(
ctx,
"nativelink-gatways",
"nativelink-gateways",
&components.NativeLinkGateways{
Dependencies: cilium,
Dependencies: slices.Concat(
cilium,
flux,
tektonOperator,
),
},
)
if err != nil {
Expand Down

0 comments on commit c2ebd7b

Please sign in to comment.