resources

package
v2.11.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package resources holds simple functions for synthesizing child resources from a Build.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DestinationImageName

func DestinationImageName(source *v1alpha1.Build, space *v1alpha1.Space) string

DestinationImageName gets the image name for an application build.

Example
build := &v1alpha1.Build{}
build.UID = "9463ad9e-4dd8-11ea-91a4-42010a80008d"
build.Name = "myapp"
build.Namespace = "myspace"

space := &v1alpha1.Space{}
space.Status.BuildConfig.ContainerRegistry = "gcr.io/my-project"

fmt.Println(DestinationImageName(build, space))
Output:

gcr.io/my-project/app_myspace_myapp:9463ad9e-4dd8-11ea-91a4-42010a80008d
Example (NoRegistry)
build := &v1alpha1.Build{}
build.UID = "32150eb9-8941-4ac9-ba23-522d902e8b81"
build.Name = "myapp"
build.Namespace = "myspace"

fmt.Println(DestinationImageName(build, &v1alpha1.Space{}))
Output:

app_myspace_myapp:32150eb9-8941-4ac9-ba23-522d902e8b81

func FindBuiltinTask

func FindBuiltinTask(cfg *config.DefaultsConfig, buildSpec v1alpha1.BuildSpec, googleServiceAccount string) *tektonv1beta1.TaskSpec

FindBuiltinTask returns a TaskSpec for a build task that's built-in to Kf. The implementation details of these tasks may change because they're not public. If no task matching the given ref is found, then nil is returned.

func MakeTaskRun

func MakeTaskRun(
	build *v1alpha1.Build,
	taskSpec *tektonv1beta1.TaskSpec,
	space *v1alpha1.Space,
	sourcePackage *v1alpha1.SourcePackage,
	secretConfig *config.SecretsConfig,
	defaultsConfig *kfconfig.DefaultsConfig,
) (*tektonv1beta1.TaskRun, error)

MakeTaskRun creates a Tekton TaskRun for a Build.

Example (CustomTask_taskRun_addedParams)
build, taskSpec := exampleCustomTaskBuild()

taskSpec.Params = append(
	taskSpec.Params,
	tektonv1beta1.ParamSpec{
		Name:        v1alpha1.TaskRunParamSourceImage,
		Type:        tektonv1beta1.ParamTypeString,
		Description: "",
		Default:     nil,
	},
	tektonv1beta1.ParamSpec{
		Name:        v1alpha1.TaskRunParamDestinationImage,
		Type:        tektonv1beta1.ParamTypeString,
		Description: "",
		Default:     tektonv1beta1.NewArrayOrString("gcr.io/test"),
	},
)

nodeSelectorMap := map[string]string{
	"disktype": "ssd",
	"cpu":      "amd64",
}

space := &v1alpha1.Space{
	Status: v1alpha1.SpaceStatus{
		BuildConfig: v1alpha1.SpaceStatusBuildConfig{
			ServiceAccount: "some-account",
		},
	},
	Spec: v1alpha1.SpaceSpec{
		RuntimeConfig: v1alpha1.SpaceSpecRuntimeConfig{
			NodeSelector: nodeSelectorMap,
		},
	},
}

taskRun, err := MakeTaskRun(build, taskSpec, space, nil, nil, nil)
if err != nil {
	panic(err)
}

fmt.Println("Name:", taskRun.Name)
fmt.Println("Label Count:", len(taskRun.Labels))
fmt.Println("Managed By:", taskRun.Labels[managedByLabel])
fmt.Println("NetworkPolicy:", taskRun.Labels[v1alpha1.NetworkPolicyLabel])
fmt.Println("Service Account:", taskRun.Spec.ServiceAccountName)
fmt.Println("OwnerReferences Count:", len(taskRun.OwnerReferences))
fmt.Println("Input Count:", len(taskRun.Spec.Params))
fmt.Println("Env Count:", len(taskRun.Spec.TaskSpec.StepTemplate.Env))
fmt.Println("Node Selector Count:", len(taskRun.Spec.PodTemplate.NodeSelector))
Output:

Name: my-build
Label Count: 2
Managed By: kf
NetworkPolicy: build
Service Account: some-account
OwnerReferences Count: 1
Input Count: 2
Env Count: 1
Node Selector Count: 3

func TaskRunName

func TaskRunName(build *v1alpha1.Build) string

TaskRunName gets the name of a TaskRun for a Build.

Example
build := &v1alpha1.Build{}
build.Name = "my-build"

fmt.Println(TaskRunName(build))
Output:

my-build

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL