Skip to content

Commit

Permalink
add generic k8sapply comp
Browse files Browse the repository at this point in the history
  • Loading branch information
fanny-jiang committed Dec 31, 2024
1 parent 3711109 commit 00e26e5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions components/kubernetes/k8sapply/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package k8sapply

import (
"fmt"
"github.com/DataDog/test-infra-definitions/common/config"
kubeComp "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type YAMLWorkload struct {
Name string
Path string
}

// K8sAppDefinition applies a generic Kubernetes resource from a YAML source file defined as a YAMLWorkload
func K8sAppDefinition(yamlWorkload YAMLWorkload) func(e config.Env, kubeProvider *kubernetes.Provider) (*kubeComp.Workload, error) {
return func(e config.Env, kubeProvider *kubernetes.Provider) (*kubeComp.Workload, error) {
k8sComponent := &kubeComp.Workload{}

if err := e.Ctx().RegisterComponentResource("dd:apps", fmt.Sprintf("k8s-apply-%s", yamlWorkload.Name), k8sComponent); err != nil {
return nil, err
}
_, err := yaml.NewConfigFile(e.Ctx(), yamlWorkload.Name, &yaml.ConfigFileArgs{
File: yamlWorkload.Path,
}, pulumi.Provider(kubeProvider), pulumi.Parent(k8sComponent))
if err != nil {
return nil, err
}
return k8sComponent, nil
}
}

0 comments on commit 00e26e5

Please sign in to comment.