1. Answers
  2. Using Kubernetes Actions.summerwind.dev With Caching.internal.knative.dev

Using Kubernetes Actions.summerwind.dev With Caching.internal.knative.dev

Introduction

In this guide, we will demonstrate how to use Kubernetes resources from the actions.summerwind.dev and caching.internal.knative.dev APIs with Pulumi. These APIs are useful for managing GitHub Actions runners and caching mechanisms within a Knative environment, respectively.

Step-by-Step Explanation

Prerequisites

Before you begin, ensure the following:

  1. Pulumi is installed and configured on your system.
  2. You have access to a Kubernetes cluster.
  3. You possess the necessary permissions to create resources in the cluster.

Setting Up the Pulumi Project

To start, you need to set up a new Pulumi project:

  1. Create a new Pulumi project:
    pulumi new typescript
    
  2. Install the necessary Pulumi packages:
    npm install @pulumi/kubernetes
    

Creating the Kubernetes Resources

Next, you’ll define the resources using Pulumi:

  1. Import the Pulumi Kubernetes package:
    import * as k8s from "@pulumi/kubernetes";
    
  2. Define the GitHub Actions runner resource:
    const runner = new k8s.apiextensions.CustomResource("runner", {
        apiVersion: "actions.summerwind.dev/v1alpha1",
        kind: "Runner",
        metadata: {
            name: "my-runner",
            namespace: "default",
        },
        spec: {
            repository: "my-org/my-repo",
            image: "my-runner-image",
            env: [
                { name: "RUNNER_TOKEN", value: "my-runner-token" },
            ],
        },
    });
    
  3. Define the Knative caching resource:
    const cache = new k8s.apiextensions.CustomResource("cache", {
        apiVersion: "caching.internal.knative.dev/v1alpha1",
        kind: "Cache",
        metadata: {
            name: "my-cache",
            namespace: "default",
        },
        spec: {
            size: "1Gi",
            path: "/cache-path",
        },
    });
    
  4. Export the resource names:
    export const runnerName = runner.metadata.name;
    export const cacheName = cache.metadata.name;
    

Key Points

  • Pulumi Setup: Start by setting up a Pulumi project and installing the necessary packages.
  • Resource Definition: Define both the GitHub Actions runner and the Knative caching resources using the Pulumi Kubernetes package.
  • Exported Resources: Ensure that the resource names are exported for use in other parts of your Pulumi program.

Summary

In this guide, we have shown how to create Kubernetes resources for GitHub Actions runners and Knative caching using Pulumi. By following these steps, you can automate the deployment and management of these resources within your Kubernetes cluster. This integration allows for efficient management of GitHub Actions and caching, enhancing your workflow automation capabilities.

Full Code Example

import * as k8s from "@pulumi/kubernetes";

const runner = new k8s.apiextensions.CustomResource("runner", {
    apiVersion: "actions.summerwind.dev/v1alpha1",
    kind: "Runner",
    metadata: {
        name: "my-runner",
        namespace: "default",
    },
    spec: {
        repository: "my-org/my-repo",
        image: "my-runner-image",
        env: [
            { name: "RUNNER_TOKEN", value: "my-runner-token" },
        ],
    },
});

const cache = new k8s.apiextensions.CustomResource("cache", {
    apiVersion: "caching.internal.knative.dev/v1alpha1",
    kind: "Cache",
    metadata: {
        name: "my-cache",
        namespace: "default",
    },
    spec: {
        size: "1Gi",
        path: "/cache-path",
    },
});

export const runnerName = runner.metadata.name;
export const cacheName = cache.metadata.name;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up