Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/atc/internal/testing/flights/identityerror/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"fmt"
"os"

"github.com/yokecd/yoke/pkg/flight"
"github.com/yokecd/yoke/pkg/flight/wasi/k8s"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

"github.com/yokecd/yoke/pkg/flight"
"github.com/yokecd/yoke/pkg/flight/wasi/k8s"
)

func main() {
Expand Down
196 changes: 196 additions & 0 deletions cmd/yoketf/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package main

import (
"context"
"flag"
"fmt"
"os"
"syscall"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
providerschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-framework/resource"
resourceschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"

"k8s.io/cli-runtime/pkg/genericclioptions"

"github.com/davidmdm/x/xcontext"

"github.com/yokecd/yoke/internal"
"github.com/yokecd/yoke/pkg/yoke"
)

func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func run() error {
var debug bool
flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
flag.Parse()

ctx, cancel := xcontext.WithSignalCancelation(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

opts := providerserver.ServeOpts{
// TODO: Update this string with the published name of your provider.
// Also update the tfplugindocs generate command to either remove the
// -provider-name flag or set its value to the updated provider name.
Address: "registry.terraform.io/yokecd/yoke",
Debug: debug,
}

return providerserver.Serve(ctx, CreateProvider, opts)
}

func CreateProvider() provider.Provider {
return new(Provider)
}

var _ provider.Provider = (*Provider)(nil)

type KubernetesConfig struct {
KubePath string `tfsdk:"config_path"`
KubeContext string `tfsdk:"config_context"`
}

type ProviderConfig struct {
Kubernetes KubernetesConfig
}

type Provider struct{}

// Configure implements [provider.Provider].
func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var cfg ProviderConfig
resp.Diagnostics.Append(req.Config.Get(ctx, &cfg)...)

kubeflags := genericclioptions.NewConfigFlags(false)
kubeflags.KubeConfig = &cfg.Kubernetes.KubePath
kubeflags.Context = &cfg.Kubernetes.KubeContext

commander, err := yoke.FromKubeConfigFlags(kubeflags)
if err != nil {
resp.Diagnostics.AddError("failed to initialize yoke client", err.Error())
}
resp.ResourceData = commander
}

// DataSources implements [provider.Provider].
func (p *Provider) DataSources(context.Context) []func() datasource.DataSource {
return nil
}

// Metadata implements [provider.Provider].
func (p *Provider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "yoke"
resp.Version = internal.GetYokeVersion()
}

// Resources implements [provider.Provider].
func (p *Provider) Resources(context.Context) []func() resource.Resource {
return []func() resource.Resource{
func() resource.Resource { return new(Release) },
}
}

// Schema implements [provider.Provider].
func (p *Provider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = providerschema.Schema{
Attributes: map[string]providerschema.Attribute{
"kubernetes": providerschema.MapNestedAttribute{
Required: true,
NestedObject: providerschema.NestedAttributeObject{
Attributes: map[string]providerschema.Attribute{
"config_path": providerschema.StringAttribute{Required: true},
"config_context": providerschema.StringAttribute{Optional: true},
},
},
},
},
Description: "",
MarkdownDescription: "",
DeprecationMessage: "",
}
}

type Release struct {
commander *yoke.Commander
}

var _ resource.Resource = (*Release)(nil)

// Create implements [resource.Resource].
func (r *Release) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
panic("unimplemented")
}

// Delete implements [resource.Resource].
func (r *Release) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
panic("unimplemented")
}

// Metadata implements [resource.Resource].
func (r *Release) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_release"
}

// Read implements [resource.Resource].
func (r *Release) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
panic("unimplemented")
}

// Schema implements [resource.Resource].
func (r *Release) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = resourceschema.Schema{
Attributes: map[string]resourceschema.Attribute{
"wasm_url": resourceschema.StringAttribute{Required: true},
"input": resourceschema.StringAttribute{Optional: true},
"args": resourceschema.ListAttribute{
Optional: true,
ElementType: types.StringType,
},
"cluster_access": resourceschema.BoolAttribute{Optional: true},
"resource_access_matchers": resourceschema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"max_memory_mib": resourceschema.Int32Attribute{Required: false},
// TODO: this needs to map onto time.Duration... Will figure that out later.
"timeout": resourceschema.StringAttribute{Required: false},
"prune": resourceschema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]resourceschema.Attribute{
"crds": resourceschema.BoolAttribute{Optional: true},
"namespaces": resourceschema.BoolAttribute{Optional: true},
},
},
},
}
}

// Update implements [resource.Resource].
func (r *Release) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
panic("unimplemented")
}

func (r *Release) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
if req.ProviderData == nil {
resp.Diagnostics.AddError("unable to configure release", "provider data not present for release configuration")
return
}

commander, ok := req.ProviderData.(*yoke.Commander)
if !ok {
resp.Diagnostics.AddError("unexpected resource configure type", fmt.Sprintf("expected *yoke.Commander but got %T", req.ProviderData))
return
}

r.commander = commander
}
20 changes: 19 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/docker/go-units v0.5.0
github.com/go-git/go-git/v5 v5.16.4
github.com/google/go-containerregistry v0.20.7
github.com/hashicorp/terraform-plugin-framework v1.17.0
github.com/jedib0t/go-pretty/v6 v6.7.8
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
github.com/stretchr/testify v1.11.1
Expand Down Expand Up @@ -61,6 +62,7 @@ require (
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
Expand All @@ -71,11 +73,20 @@ require (
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.7.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/terraform-plugin-go v0.29.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.10.0 // indirect
github.com/hashicorp/terraform-registry-address v0.4.0 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
Expand All @@ -86,11 +97,13 @@ require (
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -100,6 +113,7 @@ require (
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand All @@ -118,6 +132,8 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/vbatts/tar-split v0.12.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
Expand All @@ -130,7 +146,9 @@ require (
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/grpc v1.75.1 // indirect
google.golang.org/protobuf v1.36.9 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading
Loading