Skip to content

Commit

Permalink
update k0sctl to latest version (v0.19.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydkn committed Nov 17, 2024
1 parent 701498d commit 91eb1ef
Show file tree
Hide file tree
Showing 33 changed files with 1,046 additions and 617 deletions.
2 changes: 1 addition & 1 deletion examples/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
var myProvider = new K0s.Provider("myProvider", new()
{
NoDrain = "true",
NoDrain = true,
});

var myCluster = new K0s.Cluster("myCluster", new()
Expand Down
4 changes: 2 additions & 2 deletions examples/go/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"github.com/pulumi/pulumi-k0s/sdk/go/k0s"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/ydkn/pulumi-k0s/sdk/go/k0s"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
myProvider, err := k0s.NewProvider(ctx, "myProvider", &k0s.ProviderArgs{
NoDrain: pulumi.String("true"),
NoDrain: pulumi.Bool(true),
})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions examples/nodejs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as pulumi from "@pulumi/pulumi";
import * as k0s from "@ydkn/pulumi-k0s";
import * as k0s from "@pulumi/k0s";

const myProvider = new k0s.Provider("myProvider", {noDrain: "true"});
const myProvider = new k0s.Provider("myProvider", {noDrain: true});
const myCluster = new k0s.Cluster("myCluster", {spec: {
hosts: [{
role: "controller+worker",
Expand Down
2 changes: 1 addition & 1 deletion examples/python/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pulumi
import pulumi_k0s as k0s

my_provider = k0s.Provider("myProvider", no_drain="true")
my_provider = k0s.Provider("myProvider", no_drain=True)
my_cluster = k0s.Cluster("myCluster", spec=k0s.ClusterSpecArgs(
hosts=[k0s.ClusterHostArgs(
role="controller+worker",
Expand Down
4 changes: 2 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
go 1.21.0
go 1.23.3

toolchain go1.21.7
toolchain go1.23.3

use (
./provider
Expand Down
39 changes: 28 additions & 11 deletions provider/cluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package provider

import (
"context"
"strings"

p "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
Expand Down Expand Up @@ -38,6 +41,7 @@ type ClusterHost struct {
Hooks *ClusterHooks `pulumi:"hooks,optional" json:"hooks,omitempty"`
WinRM *ClusterWinRM `pulumi:"winRM,optional" json:"winRM,omitempty"`
SSH *ClusterSSH `pulumi:"ssh,optional" json:"ssh,omitempty"`
OpenSSH *ClusterOpenSSH `pulumi:"openSSH,optional" json:"openSSH,omitempty"`
Localhost *ClusterLocalhost `pulumi:"localhost,optional" json:"localhost,omitempty"`
NoTaints *bool `pulumi:"noTaints,optional" json:"noTaints,omitempty"`
}
Expand Down Expand Up @@ -88,6 +92,16 @@ type ClusterSSH struct {
Bastion *ClusterSSH `pulumi:"bastion,optional" json:"bastion,omitempty"`
}

type ClusterOpenSSH struct {
Address *string `pulumi:"address" json:"address,omitempty"`
Port *int `pulumi:"port,optional" json:"port,omitempty"`
User *string `pulumi:"user,optional" json:"user,omitempty"`
Key *string `pulumi:"key,optional" provider:"secret" json:"-"`
ConfigPath *string `pulumi:"configPath,optional" json:"configPath,omitempty"`
Options map[string]any `pulumi:"options,optional" json:"options,omitempty"`
DisableMultiplexing bool `pulumi:"disableMultiplexing,optional" json:"disableMultiplexing,omitempty"`
}

type ClusterLocalhost struct {
Enabled *bool `pulumi:"enabled,optional" json:"enabled,omitempty"`
}
Expand Down Expand Up @@ -317,7 +331,7 @@ type ClusterOutputs struct {
type Cluster struct{}

func (c Cluster) Check(
ctx p.Context,
ctx context.Context,
name string,
olds ClusterOutputs,
news ClusterInputs,
Expand All @@ -336,7 +350,12 @@ func (c Cluster) Check(
return news, failures, nil
}

func (c Cluster) Diff(ctx p.Context, name string, olds ClusterOutputs, news ClusterInputs) (p.DiffResponse, error) {
func (c Cluster) Diff(
ctx context.Context,
name string,
olds ClusterOutputs,
news ClusterInputs,
) (p.DiffResponse, error) {
diffResponse := p.DiffResponse{
DeleteBeforeReplace: true,
HasChanges: false,
Expand All @@ -349,16 +368,16 @@ func (c Cluster) Diff(ctx p.Context, name string, olds ClusterOutputs, news Clus

oldsProps, err := introspect.NewPropertiesMap(olds)
if err != nil {
return p.DiffResponse{}, err
return diffResponse, err
}

newsProps, err := introspect.NewPropertiesMap(news)
if err != nil {
return p.DiffResponse{}, err
return diffResponse, err
}

for key := range propertyMapDiff(oldsProps, newsProps, []resource.PropertyKey{"kubeconfig"}) {
diffResponse.DetailedDiff[string(key)] = p.PropertyDiff{
diffResponse.DetailedDiff[strings.SplitN(string(key), ".", 2)[0]] = p.PropertyDiff{
Kind: p.Update,
InputDiff: true,
}
Expand All @@ -372,7 +391,7 @@ func (c Cluster) Diff(ctx p.Context, name string, olds ClusterOutputs, news Clus
}

func (c *Cluster) Read(
ctx p.Context,
ctx context.Context,
name string,
news ClusterInputs,
olds ClusterOutputs,
Expand All @@ -396,7 +415,7 @@ func (c *Cluster) Read(
}

func (c Cluster) Create(
ctx p.Context,
ctx context.Context,
name string,
news ClusterInputs,
preview bool,
Expand Down Expand Up @@ -427,7 +446,7 @@ func (c Cluster) Create(
}

func (c Cluster) Update(
ctx p.Context,
ctx context.Context,
name string,
olds ClusterOutputs,
news ClusterInputs,
Expand Down Expand Up @@ -459,7 +478,7 @@ func (c Cluster) Update(
return olds, nil
}

func (c Cluster) Delete(ctx p.Context, name string, olds ClusterOutputs) error {
func (c Cluster) Delete(ctx context.Context, name string, olds ClusterOutputs) error {
manager, err := c.newManager(name, &olds.ClusterInputs)
if err != nil {
return err
Expand All @@ -469,8 +488,6 @@ func (c Cluster) Delete(ctx p.Context, name string, olds ClusterOutputs) error {
return err
}

olds.Kubeconfig = nil

return nil
}

Expand Down
72 changes: 62 additions & 10 deletions provider/config.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,82 @@
package provider

import (
"context"
"strings"

p "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/ydkn/pulumi-k0s/provider/internal/introspect"
)

type Config struct {
SkipDowngradeCheck *string `pulumi:"skipDowngradeCheck,optional"`
NoDrain *string `pulumi:"noDrain,optional"`
NoWait *string `pulumi:"noWait,optional"`
Concurrency *string `pulumi:"concurrency,optional"`
ConcurrentUploads *string `pulumi:"concurrentUploads,optional"`
SkipDowngradeCheck *bool `pulumi:"skipDowngradeCheck,optional"`
NoDrain *bool `pulumi:"noDrain,optional"`
NoWait *bool `pulumi:"noWait,optional"`
Concurrency *int `pulumi:"concurrency,optional"`
ConcurrentUploads *int `pulumi:"concurrentUploads,optional"`
}

func (c *Config) Annotate(a infer.Annotator) {
skipDowngradeCheckValue := false
a.Describe(&c.SkipDowngradeCheck, "Skip downgrade check")
a.SetDefault(&c.SkipDowngradeCheck, "false", "PULUMI_K0S_SKIP_DOWNGRADE_CHECK")
a.SetDefault(&c.SkipDowngradeCheck, &skipDowngradeCheckValue, "PULUMI_K0S_SKIP_DOWNGRADE_CHECK")

noDrainValue := false
a.Describe(&c.NoDrain, "Do not drain worker nodes when upgrading")
a.SetDefault(&c.NoDrain, "false", "PULUMI_K0S_NO_DRAIN")
a.SetDefault(&c.NoDrain, &noDrainValue, "PULUMI_K0S_NO_DRAIN")

noWaitValue := false
a.Describe(&c.NoWait, "Do not wait for worker nodes to join")
a.SetDefault(&c.NoWait, "false", "PULUMI_K0S_NO_WAIT")
a.SetDefault(&c.NoWait, &noWaitValue, "PULUMI_K0S_NO_WAIT")

concurrencyValue := 30
a.Describe(&c.Concurrency, "Maximum number of hosts to configure in parallel, set to 0 for unlimited")
a.SetDefault(&c.Concurrency, "30", "PULUMI_K0S_CONCURRENCY")
a.SetDefault(&c.Concurrency, &concurrencyValue, "PULUMI_K0S_CONCURRENCY")

concurrentUploadsValue := 5
a.Describe(&c.ConcurrentUploads, "Maximum number of files to upload in parallel, set to 0 for unlimited")
a.SetDefault(&c.ConcurrentUploads, "5", "PULUMI_K0S_CONCURRENT_UPLOADS")
a.SetDefault(&c.ConcurrentUploads, &concurrentUploadsValue, "PULUMI_K0S_CONCURRENT_UPLOADS")
}

func (c *Config) Diff(ctx context.Context, name string, olds Config, news Config) (p.DiffResponse, error) {
diffResponse := p.DiffResponse{
DeleteBeforeReplace: false,
HasChanges: false,
DetailedDiff: map[string]p.PropertyDiff{},
}

oldsProps, err := introspect.NewPropertiesMap(olds)
if err != nil {
return p.DiffResponse{}, err
}

newsProps, err := introspect.NewPropertiesMap(news)
if err != nil {
return p.DiffResponse{}, err
}

for key := range propertyMapDiff(oldsProps, newsProps, []resource.PropertyKey{}) {
diffResponse.DetailedDiff[strings.SplitN(string(key), ".", 2)[0]] = p.PropertyDiff{
Kind: p.Update,
InputDiff: true,
}
}

if len(diffResponse.DetailedDiff) > 0 {
diffResponse.HasChanges = true
}

return diffResponse, nil
}

func (c *Config) Check(ctx context.Context, name string, olds Config, news Config) (Config, []p.CheckFailure, error) {
return Config{
SkipDowngradeCheck: news.SkipDowngradeCheck,
NoDrain: news.NoDrain,
NoWait: news.NoWait,
Concurrency: news.Concurrency,
ConcurrentUploads: news.ConcurrentUploads,
}, []p.CheckFailure{}, nil
}
Loading

0 comments on commit 91eb1ef

Please sign in to comment.