### Install kpoward Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/goccy/kpoward/README.md Install the kpoward library using go get. ```console go get github.com/goccy/kpoward ``` -------------------------------- ### Install go-version Library Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/hashicorp/go-version/README.md Install the go-version library using the standard go get command. ```bash $ go get github.com/hashicorp/go-version ``` -------------------------------- ### Custom Decoder Example Setup Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/kelseyhightower/envconfig/README.md Sets an environment variable for a custom decoder example. ```Bash export DNS_SERVER=8.8.8.8 ``` -------------------------------- ### Example: Setup Failure with t.Fatalf() Source: https://github.com/tektoncd/pipeline/blob/main/docs/developers/testing-best-practices.md Use t.Fatalf() when test setup fails, as continuing the test is impossible or unsafe without the necessary clients. ```go func TestTaskRunReconcile(t *testing.T) { clients, err := test.NewClients(kubeconfig, cluster, namespace) if err != nil { t.Fatalf("failed to create test clients: %v", err) } // Test continues - clients are guaranteed to be valid } ``` -------------------------------- ### Install OTLP Prometheus Translator Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/prometheus/otlptranslator/README.md Install the library using go get. ```bash go get github.com/prometheus/otlptranslator ``` -------------------------------- ### Install Flect Package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/gobuffalo/flect/README.md Install the Flect package using the go get command. ```console $ go get github.com/gobuffalo/flect ``` -------------------------------- ### Install sigs.k8s.io/yaml Source: https://github.com/tektoncd/pipeline/blob/main/vendor/sigs.k8s.io/yaml/README.md Install the YAML package using go get. ```bash $ go get sigs.k8s.io/yaml ``` -------------------------------- ### Install Kind and Set Up Tekton Cluster Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/tektoncd/plumbing/DEVELOPMENT.md Installs the kind tool and sets up a new Tekton cluster. Ensure Go 1.14+ and Docker are installed. ```bash # Install Kind if not installed yet GO111MODULE="on" go get sigs.k8s.io/kind@v0.9.0 # Delete any pre-existing Tekton cluster kind delete cluster --name tekton # Install the new cluster ./hack/tekton_in_kind.sh ``` -------------------------------- ### Install IAM Go Client Source: https://github.com/tektoncd/pipeline/blob/main/vendor/cloud.google.com/go/iam/README.md Use this command to install the IAM Go client library. Ensure you have Go installed and configured. ```bash go get cloud.google.com/go/iam ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/json-iterator/go/README.md Use the go get command to install the json-iterator/go library. ```go go get github.com/json-iterator/go ``` -------------------------------- ### Basic WebService Setup and Route Definition Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/emicklei/go-restful/v3/README.md Defines a new WebService, sets its path and supported MIME types, and defines a GET route for retrieving a user by ID. The route includes documentation and parameter definitions. ```go ws := new(restful.WebService) ws. Path("/users"). Consumes(restful.MIME_XML, restful.MIME_JSON). Produces(restful.MIME_JSON, restful.MIME_XML) ws.Route(ws.GET("/{user-id}").To(u.findUser). Doc("get a user"). Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). Writes(User{})) ``` -------------------------------- ### Install blackfriday-tool Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/russross/blackfriday/v2/README.md Installs the blackfriday-tool command-line utility. ```go go get github.com/russross/blackfriday-tool ``` -------------------------------- ### Install Google Auth Library for Go Source: https://github.com/tektoncd/pipeline/blob/main/vendor/cloud.google.com/go/auth/README.md Install the latest version of the Google Auth library for Go using the go get command. ```bash go get cloud.google.com/go/auth@latest ``` -------------------------------- ### Implement Initialize Method for Resolver Source: https://github.com/tektoncd/pipeline/blob/main/docs/how-to-write-a-resolver.md The `Initialize` method is used to set up any prerequisites for the resolver. This example shows an implementation that requires no setup and returns nil. ```go // Initialize sets up any dependencies needed by the resolver. None atm. func (r *resolver) Initialize(context.Context) error { return nil } ``` -------------------------------- ### Install uuid Package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/google/uuid/README.md Use 'go get' to install the uuid package. This command fetches and installs the package and its dependencies. ```sh go get github.com/google/uuid ``` -------------------------------- ### Install copystructure Go Library Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/mitchellh/copystructure/README.md Install the copystructure library using the standard Go get command. ```bash go get github.com/mitchellh/copystructure ``` -------------------------------- ### Install yaml package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/go.yaml.in/yaml/v3/README.md Install the yaml package for Go using the go get command. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/mitchellh/mapstructure/README.md Use standard go get command to install the mapstructure library. ```bash go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Create Pipeline Resource Example Source: https://github.com/tektoncd/pipeline/blob/main/test/README.md Example of creating a Pipeline resource using the initialized clients. Assumes namespaceName and pipelineName are defined. ```bash _, err = clients.v1PipelineClient.Pipelines.Create(test.Route(namespaceName, pipelineName)) ``` -------------------------------- ### Install a Google Cloud Go Package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/cloud.google.com/go/README.md Use 'go get' to install a specific Google Cloud client library package. Replace 'firestore' with the desired package name. ```bash go get cloud.google.com/go/firestore@latest # Replace firestore with the package you want to use. ``` -------------------------------- ### Install cosign Source: https://github.com/tektoncd/pipeline/blob/main/docs/additional-configs.md Install the cosign tool using Go. This is a prerequisite for verifying image signatures. ```shell go install github.com/sigstore/cosign/cmd/cosign@latest ``` -------------------------------- ### Install Azure Key Vault and Identity Packages Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys/README.md Install the necessary Azure SDK for Go packages for key vault and identity management using go get. ```Bash go get github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys go get github.com/Azure/azure-sdk-for-go/sdk/azidentity ``` -------------------------------- ### Install Compute Metadata Go Library Source: https://github.com/tektoncd/pipeline/blob/main/vendor/cloud.google.com/go/compute/metadata/README.md Use this command to install the compute metadata Go library. ```bash go get cloud.google.com/go/compute/metadata ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/tektoncd/pipeline/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs and runs a local Go Doc site using pkgsite. Ensure you have Go installed and the latest version of pkgsite is available. ```sh go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install go-sockaddr CLI Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/hashicorp/go-sockaddr/README.md Installs the go-sockaddr command-line utility. This tool exposes most of the library's functionality. ```text $ go install github.com/hashicorp/go-sockaddr/cmd/sockaddr@latest ``` -------------------------------- ### Start Minikube Session Source: https://github.com/tektoncd/pipeline/blob/main/docs/developers/local-setup.md Starts a Minikube cluster with specified memory and CPU resources. ```bash minikube start --memory 6144 --cpus 2 ``` -------------------------------- ### Install the "demo" Resolver Source: https://github.com/tektoncd/pipeline/blob/main/docs/resolver-template/README.md Use 'ko apply' to install the demo Resolver. Ensure you have kubectl and ko installed, and the tekton-pipelines namespace and ResolutionRequest controller are set up. ```bash ko apply -f ./config/demo-resolver-deployment.yaml ``` -------------------------------- ### Install the longrunning Library Source: https://github.com/tektoncd/pipeline/blob/main/vendor/cloud.google.com/go/longrunning/README.md Use this command to install the Go library for long-running operations. ```bash go get cloud.google.com/go/longrunning ``` -------------------------------- ### List Tags for a Repository Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/README.md This example demonstrates how to list tags for a specific repository (e.g., gcr.io/google-containers/pause) by making a direct HTTP GET request to the registry's tags list endpoint. It includes fetching credentials, constructing an authenticated HTTP client, and handling potential errors. ```go package main import ( "io" "net/http" "os" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote/transport" ) func main() { repo, err := name.NewRepository("gcr.io/google-containers/pause") if err != nil { panic(err) } // Fetch credentials based on your docker config file, which is $HOME/.docker/config.json or $DOCKER_CONFIG. auth, err := authn.DefaultKeychain.Resolve(repo.Registry) if err != nil { panic(err) } // Construct an http.Client that is authorized to pull from gcr.io/google-containers/pause. scopes := []string{repo.Scope(transport.PullScope)} t, err := transport.New(repo.Registry, auth, http.DefaultTransport, scopes) if err != nil { panic(err) } client := &http.Client{Transport: t} // Make the actual request. resp, err := client.Get("https://gcr.io/v2/google-containers/pause/tags/list") if err != nil { panic(err) } // Assert that we get a 200, otherwise attempt to parse body as a structured error. if err := transport.CheckError(resp, http.StatusOK); err != nil { panic(err) } // Write the response to stdout. if _, err := io.Copy(os.Stdout, resp.Body); err != nil { panic(err) } } ``` -------------------------------- ### Install Gorilla WebSocket Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/gorilla/websocket/README.md Use this command to install the Gorilla WebSocket package for your Go project. ```go go get github.com/gorilla/websocket ``` -------------------------------- ### Set Environment Variables for Usage Example Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/kelseyhightower/envconfig/README.md Example environment variables to be processed by the envconfig library. ```Bash export MYAPP_DEBUG=false export MYAPP_PORT=8080 export MYAPP_USER=Kelsey export MYAPP_RATE="0.5" export MYAPP_TIMEOUT="3m" export MYAPP_USERS="rob,ken,robert" export MYAPP_COLORCODES="red:1,green:2,blue:3" ``` -------------------------------- ### Instantiation with Options Source: https://github.com/tektoncd/pipeline/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Demonstrates how to instantiate an object using a variadic Option parameter. Required parameters can precede the options. ```go func NewT(options ...Option) T {…} ``` -------------------------------- ### Initialize Controller Implementation Source: https://github.com/tektoncd/pipeline/blob/main/vendor/knative.dev/pkg/injection/README.md Use NewImpl to get an injection-based client and lister for a kind, set up event recorders, and delegate queue management to controller.NewContext. ```go impl := reconciler.NewImpl(ctx, reconcilerInstance) ``` -------------------------------- ### Install Latest JSON-Patch Source: https://github.com/tektoncd/pipeline/blob/main/vendor/gopkg.in/evanphx/json-patch.v4/README.md Install the latest version of the jsonpatch library using go get. ```bash go get -u github.com/evanphx/json-patch/v5 ``` -------------------------------- ### Install go.uber.org/multierr Source: https://github.com/tektoncd/pipeline/blob/main/vendor/go.uber.org/multierr/README.md Install the latest version of the multierr library using the go get command. ```bash go get -u go.uber.org/multierr@latest ``` -------------------------------- ### Simple BigCache Initialization Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/allegro/bigcache/v3/README.md Demonstrates basic initialization of BigCache with default configuration and setting/getting an entry. ```go import ( "fmt" "context" "github.com/allegro/bigcache/v3" ) cache, _ := bigcache.New(context.Background(), bigcache.DefaultConfig(10 * time.Minute)) cache.Set("my-unique-key", []byte("value")) entry, _ := cache.Get("my-unique-key") fmt.Println(string(entry)) ``` -------------------------------- ### Install JSON-Patch Version 4 Source: https://github.com/tektoncd/pipeline/blob/main/vendor/gopkg.in/evanphx/json-patch.v4/README.md Install version 4 of the jsonpatch library using go get. ```bash go get -u gopkg.in/evanphx/json-patch.v4 ``` -------------------------------- ### Create Key using keyvault module Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys/MIGRATION.md Demonstrates creating a key using the older `keyvault` module. Requires `keyvault` and `kvauth` packages. Authentication is handled via `Authorizer`. ```go import ( "context" "fmt" "github.com/Azure/azure-sdk-for-go/profiles/latest/keyvault/keyvault" kvauth "github.com/Azure/azure-sdk-for-go/services/keyvault/auth" ) func main() { vaultURL := "https://.vault.azure.net" authorizer, err := kvauth.NewAuthorizerFromEnvironment() if err != nil { // TODO: handle error } basicClient := keyvault.New() basicClient.Authorizer = authorizer fmt.Println("\ncreating a key in keyvault:") keyParams := keyvault.KeyCreateParameters{ Curve: &keyvault.P256, Kty: &keyvault.EC, } newBundle, err := basicClient.CreateKey(context.TODO(), vaultURL, "", keyParams) if err != nil { // TODO: handle error } fmt.Println("added/updated: " + *newBundle.JSONWebKey.Kid) } ``` -------------------------------- ### Entrypoint with Wait File Content Check Source: https://github.com/tektoncd/pipeline/blob/main/cmd/entrypoint/README.md This example demonstrates waiting for a file to exist and contain content before executing a command. It's useful for synchronizing with sidecar readiness. ```shell entrypoint \ -wait_file /tekton/downward/ready \ -wait_file_contents \ -post_file /tekton/run/1/out \ -entrypoint bash -- \ echo hello ``` -------------------------------- ### Install Tekton Source: https://github.com/tektoncd/pipeline/blob/main/tekton/README.md Installs Tekton using a specified version. Requires cluster-admin privileges for initial setup. ```bash kubectl create clusterrolebinding cluster-admin-binding-someusername \ --clusterrole=cluster-admin \ --user=$(gcloud config get-value core/account) # Example, Tekton v0.9.1 export TEKTON_VERSION=0.9.1 kubectl apply --filename https://infra.tekton.dev/tekton-releases/pipeline/previous/v${TEKTON_VERSION}/release.yaml ``` -------------------------------- ### Install jwt-go Package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/golang-jwt/jwt/v5/README.md Install the jwt-go package as a dependency in your Go program using the go get command. ```sh go get -u github.com/golang-jwt/jwt/v5 ``` -------------------------------- ### Enable and Configure Logging Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/containers/azcontainerregistry/TROUBLESHOOTING.md This example demonstrates how to enable logging for the Azure SDK for Go and configure the listener to print specific event types (requests and responses) to standard output. ```Go import azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log" // Print log events to stdout azlog.SetListener(func(cls azlog.Event, msg string) { fmt.Println(msg) }) // Includes only requests and responses in credential logs azlog.SetEvents(azlog.EventRequest, azlog.EventResponse) ``` -------------------------------- ### Install githubv4 Package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/shurcooL/githubv4/README.md Install the githubv4 package using go get. Requires Go version 1.8 or later. ```bash go get -u github.com/shurcooL/githubv4 ``` -------------------------------- ### Install graphql Package Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/shurcooL/graphql/README.md Use go get to install the graphql package. Requires Go version 1.8 or later. ```bash go get -u github.com/shurcooL/graphql ``` -------------------------------- ### Starting Controllers with Shared Main Source: https://github.com/tektoncd/pipeline/blob/main/vendor/knative.dev/pkg/injection/README.md Uses the sharedmain.Main function to set up and run controllers. Import controller packages and pass their constructors to the Main function. ```go package main import ( // The set of controllers this process will run. "github.com/knative/foo/pkg/reconciler/bar" "github.com/knative/baz/pkg/reconciler/blah" // This defines the shared main for injected controllers. "knative.dev/pkg/injection/sharedmain" ) func main() { sharedmain.Main("componentname", bar.NewController, blah.NewController, ) } ``` -------------------------------- ### Initialize Resolver Binary (Latest Framework) Source: https://github.com/tektoncd/pipeline/blob/main/docs/how-to-write-a-resolver.md Sets up the main function for a Tekton Resolver using the latest framework. This code is the entry point for the resolver program. ```go package main import ( "context" "github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/framework" "knative.dev/pkg/injection/sharedmain" ) func main() { sharedmain.Main("controller", framework.NewController(context.Background(), &resolver{}), ) } type resolver struct {} ``` -------------------------------- ### Basic StepAction Example Source: https://github.com/tektoncd/pipeline/blob/main/docs/stepactions.md This example demonstrates a basic StepAction with environment variables, image, command, and arguments. Ensure the image used adheres to the container contract. ```yaml apiVersion: tekton.dev/v1beta1 kind: StepAction metadata: name: example-stepaction-name spec: env: - name: HOME value: /home image: ubuntu command: ["ls"] args: ["-lh"] ``` -------------------------------- ### Install Latest Official Tekton Pipelines Release Source: https://github.com/tektoncd/pipeline/blob/main/docs/install.md Use this command to install the latest stable release of Tekton Pipelines on your Kubernetes cluster. This is suitable for quick starts but not recommended for production environments. ```bash kubectl apply --filename https://infra.tekton.dev/tekton-releases/pipeline/latest/release.yaml ``` -------------------------------- ### SpdyStream Client Example Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/moby/spdystream/README.md Connects to a mirroring server and creates a stream to send and receive data. Ensure a mirroring server is running on localhost:8080. ```go package main import ( "fmt" "github.com/moby/spdystream" "net" "net/http" ) func main() { conn, err := net.Dial("tcp", "localhost:8080") if err != nil { panic(err) } spdyConn, err := spdystream.NewConnection(conn, false) if err != nil { panic(err) } go spdyConn.Serve(spdystream.NoOpStreamHandler) stream, err := spdyConn.CreateStream(http.Header{}, nil, false) if err != nil { panic(err) } stream.Wait() fmt.Fprint(stream, "Writing to stream") buf := make([]byte, 25) stream.Read(buf) fmt.Println(string(buf)) stream.Close() } ``` -------------------------------- ### Verify Tekton Installation Source: https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md Check if Tekton pipeline pods are running in the 'tekton-pipelines' namespace using 'kubectl get pods'. ```shell kubectl get pods -n tekton-pipelines ``` -------------------------------- ### Reference Remote Pipeline from Git Source: https://github.com/tektoncd/pipeline/blob/main/docs/pipelineruns.md Example of referencing a Pipeline located in a remote Git repository. This is a beta feature and requires specific resolvers to be installed. ```yaml spec: pipelineRef: resolver: git params: - name: url value: https://github.com/tektoncd/catalog.git - name: revision value: abc123 - name: pathInRepo value: /pipeline/buildpacks/0.1/buildpacks.yaml ``` -------------------------------- ### Initialize Resolver Binary (Previous Framework) Source: https://github.com/tektoncd/pipeline/blob/main/docs/how-to-write-a-resolver.md Sets up the main function for a Tekton Resolver using a deprecated framework. This code serves as the entry point for the resolver program. ```go package main import ( "context" "github.com/tektoncd/pipeline/pkg/resolution/resolver/framework" "knative.dev/pkg/injection/sharedmain" ) func main() { sharedmain.Main("controller", framework.NewController(context.Background(), &resolver{}), ) } type resolver struct {} ``` -------------------------------- ### Main Function for Webhook Setup Source: https://github.com/tektoncd/pipeline/blob/main/vendor/knative.dev/pkg/webhook/README.md Sets up the main context with webhook options and runs the shared main function, including the certificate controller and the resource admission controller. ```go func main() { // Set up a signal context with our webhook options. ctx := webhook.WithOptions(signals.NewContext(), webhook.Options{ // The name of the Kubernetes service selecting over this deployment's pods. ServiceName: "webhook", // The port on which to serve. Port: 8443, // The name of the secret containing certificate data. SecretName: "webhook-certs", }) sharedmain.MainWithContext(ctx, "webhook", // The certificate controller will ensure that the named secret (above) has // the appropriate shape for our webhook's admission controllers. certificates.NewController, // This invokes the method defined above to instantiate the resource admission // controller. NewResourceAdmissionController, ) } ``` -------------------------------- ### TaskRun Referencing Remote StepAction from Git Source: https://github.com/tektoncd/pipeline/blob/main/docs/stepactions.md This example demonstrates how to reference a StepAction located in a remote Git repository using the 'git' resolver. Ensure your cluster has the necessary resolvers installed. ```yaml apiVersion: tekton.dev/v1 kind: TaskRun metadata: generateName: step-action-run- spec: taskSpec: steps: - name: action-runner ref: resolver: git params: - name: url value: https://github.com/repo/repo.git - name: revision value: main - name: pathInRepo value: remote_step.yaml ``` -------------------------------- ### Example: Helper Function Using t.Fatalf() Source: https://github.com/tektoncd/pipeline/blob/main/docs/developers/testing-best-practices.md Helper functions for test setup or must-succeed operations should use t.Fatalf() directly to fail fast and simplify test code. This is an idiomatic Go pattern. ```go func mustCreateTaskRun(t *testing.T, name string) *v1.TaskRun { t.Helper() tr := &v1.TaskRun{ ObjectMeta: metav1.ObjectMeta{Name: name}, } created, err := clients.TektonClient.TaskRuns("default").Create(ctx, tr, metav1.CreateOptions{}) if err != nil { t.Fatalf("failed to create TaskRun: %v", err) } return created } ``` -------------------------------- ### Create Root Logger in Main Function Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/go-logr/logr/README.md Demonstrates how to create the root logger using a specific implementation (e.g., 'logimpl') with initial parameters early in the application's lifecycle. ```go func main() { // ... other setup code ... // Create the "root" logger. We have chosen the "logimpl" implementation, // which takes some initial parameters and returns a logr.Logger. logger := logimpl.New(param1, param2) // ... other setup code ... } ``` -------------------------------- ### Step with Command and Args Source: https://github.com/tektoncd/pipeline/blob/main/docs/container-contract.md This example illustrates how to provide arguments to a command specified for a step within a Task. Environment variables can also be set for the step. ```yaml steps: - image: ubuntu command: ["/bin/bash"] args: ["-c", "echo hello $FOO"] env: - name: "FOO" value: "world" ``` -------------------------------- ### Successful TaskRun Status Example Source: https://github.com/tektoncd/pipeline/blob/main/docs/taskruns.md This YAML snippet shows the `status` field of a successfully executed TaskRun, detailing completion time, conditions, pod name, start time, and step execution information. ```yaml completionTime: "2019-08-12T18:22:57Z" conditions: - lastTransitionTime: "2019-08-12T18:22:57Z" message: All Steps have completed executing reason: Succeeded status: "True" type: Succeeded podName: status-taskrun-pod startTime: "2019-08-12T18:22:51Z" steps: - container: step-hello imageID: docker-pullable://busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 name: hello terminationReason: Completed terminated: containerID: docker://d5a54f5bbb8e7a6fd3bc7761b78410403244cf4c9c5822087fb0209bf59e3621 exitCode: 0 finishedAt: "2019-08-12T18:22:56Z" reason: Completed startedAt: "2019-08-12T18:22:54Z" ``` -------------------------------- ### Add Go Bin Directory to PATH Source: https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md Appends the Go binary directory to the system's PATH environment variable. This allows executables installed via `go get` to be run from any terminal location. ```shell export PATH="${PATH}:$HOME/go/bin" ``` -------------------------------- ### Coexist with glog using klog Source: https://github.com/tektoncd/pipeline/blob/main/vendor/k8s.io/klog/v2/README.md Example demonstrating how to initialize and synchronize flags between glog and klog, and use stderr for combined output. ```go package main import ( "flag" "github.com/golang/glog" "k8s.io/klog/v2" ) func main() { // Initialize glog flags glog.InitFlags() // Initialize klog flags and synchronize with glog's flags klog.InitFlags(nil) // Set alsologtostderr to true for combined output to stderr flag.Set("alsologtostderr", "true") glog.Info("This is a glog message.") klog.Info("This is a klog message.") } ``` -------------------------------- ### Initialize Observability Explicitly in Constructor Source: https://github.com/tektoncd/pipeline/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Initialize instrumentation explicitly within a constructor function to ensure clear ownership and scope, avoiding global or implicit side effects. This example shows proper setup for observability metrics. ```go import ( "errors" semconv "go.opentelemetry.io/otel/semconv/v1.41.0" "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" ) type SDKComponent struct { inst *instrumentation } func NewSDKComponent(config Config) (*SDKComponent, error) { inst, err := newInstrumentation() if err != nil { return nil, err } return &SDKComponent{inst: inst}, nil } type instrumentation struct { inflight otelconv.SDKComponentInflight exported otelconv.SDKComponentExported } func newInstrumentation() (*instrumentation, error) { if !x.Observability.Enabled() { return nil, nil } meter := otel.GetMeterProvider().Meter( "", metric.WithInstrumentationVersion(sdk.Version()), metric.WithSchemaURL(semconv.SchemaURL), ) inst := &instrumentation{} var err, e error inst.inflight, e = otelconv.NewSDKComponentInflight(meter) err = errors.Join(err, e) inst.exported, e = otelconv.NewSDKComponentExported(meter) err = errors.Join(err, e) return inst, err } ``` ```go // ❌ Avoid this pattern. func (c *Component) initObservability() { // Initialize observability metrics if !x.Observability.Enabled() { return } // Initialize observability metrics c.inst = &instrumentation{/* ... */} } ``` -------------------------------- ### Compile Cosign and Example Plugin Source: https://github.com/tektoncd/pipeline/blob/main/vendor/github.com/sigstore/sigstore/pkg/signature/kms/cliplugin/README.md Compile the cosign CLI and the example local KMS plugin. Ensure the compiled binaries are accessible in your PATH. ```shell go build -C cosign/cmd/cosign -o `pwd`/cosign-cli go build -C sigstore/test/cliplugin/localkms -o `pwd`/sigstore-kms-localkms ``` -------------------------------- ### Install Gotestsum for Improved Test Output Source: https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md Installs the gotestsum tool, which enhances the formatting of test output. Once installed, `make test-unit` will automatically utilize it. ```shell go install gotest.tools/gotestsum@latest ```