Skip to content

Commit

Permalink
Merge pull request #508 from threefoldtech/development_k8s_same_flist_
Browse files Browse the repository at this point in the history
use same flist for k8s cluster master and workers
  • Loading branch information
rawdaGastan authored Sep 25, 2024
2 parents 0e69242 + a462078 commit 8289dce
Show file tree
Hide file tree
Showing 19 changed files with 552 additions and 553 deletions.
20 changes: 9 additions & 11 deletions docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,15 @@ func main() {
}
kubernetes, err := threefold.NewKubernetes(ctx, "kubernetes", &threefold.KubernetesArgs{
Master: &threefold.K8sNodeInputArgs{
VMInput: &threefold.VMInput{
Name: pulumi.String("kubernetes"),
Network_name: pulumi.String("test"),
NodeID: scheduler.Nodes.ApplyT(func(nodes []int) (int, error) {
return nodes[0], nil
}).(pulumi.IntOutput),
Planetary: pulumi.Bool(true),
Mycelium: pulumi.Bool(true),
Cpu: pulumi.Int(2),
Memory: pulumi.Int(2048),
},
Name: pulumi.String("kubernetes"),
Network_name: pulumi.String("test"),
NodeID: scheduler.Nodes.ApplyT(func(nodes []int) (int, error) {
return nodes[0], nil
}).(pulumi.IntOutput),
Planetary: pulumi.Bool(true),
Mycelium: pulumi.Bool(true),
Cpu: pulumi.Int(2),
Memory: pulumi.Int(2048),
Disk_size: pulumi.Int(2),
},
Workers: threefold.K8sNodeInputArray{
Expand Down
7 changes: 2 additions & 5 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,12 @@ github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ=
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.11 h1:FmEQplYSZ6pYslmBlUNaUabScOdi6hJialeV/yq0BrY=
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.11/go.mod h1:Obsv0kspgSSwF8jb91Z7CBY2FCQNq6RhiZXIQf26nWY=
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17 h1:JwjhOz4mSV0qL0/oF+fdLYtE+l0s7fFjObunzTairYA=
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17/go.mod h1:MwKEEeKN7qApCdabKRBTs18lrJ6JzA2Xx5Hd2/zb4o0=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.10 h1:If91FVqQgd2mZutMMUIrapsqZKDN8/hL5r5Yfr+vFK0=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.10/go.mod h1:yg1BDRR/TSr87mkjxEfsKc0VzMTJcbg87WW7C0GUPXQ=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.11 h1:qsSICIj5cvoVBR4GLWmdu2n3FfJG5isJ2ABnNNWykLU=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.11/go.mod h1:7cKHvKPpfdCpU4a/VCznRDDNMPBPI98cJ0uVJoUGrgg=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.17 h1:rI9viGoLdgMX62Y1nFN6Utjbjp3ovZRfzImZBeNB5K4=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.17/go.mod h1:2Z7uJYHeilN7bASpmkcDxtl+3AT8tim6iIvqZ08pwCg=
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.17/go.mod h1:cDTivSsUl4r1jN+H8/W6yDqByOOliY8HEGuVuL3ixV8=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.16 h1:Bnt9POje9hc9nv1YwAu13ABnl63DBMH0qL4SeVhNsIQ=
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.16/go.mod h1:2Z7uJYHeilN7bASpmkcDxtl+3AT8tim6iIvqZ08pwCg=
github.com/threefoldtech/zbus v1.0.1/go.mod h1:E/v/xEvG/l6z/Oj0aDkuSUXFm/1RVJkhKBwDTAIdsHo=
github.com/threefoldtech/zos v0.5.6-0.20240611092312-66184cdeb953 h1:hzqMY2Ydb+N2TBrTJHpy5n5i5nflfre1dhoNQH/tfhI=
github.com/threefoldtech/zos v0.5.6-0.20240611092312-66184cdeb953/go.mod h1:yH6T43SiHvQBBuLgKGElECsIhqzJ6fy/dJyaxtO/X0M=
Expand Down
26 changes: 23 additions & 3 deletions provider/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package provider

import (
"fmt"
"os"

"github.com/pulumi/pulumi-go-provider/infer"
)

// TODO: computed

var _ = (infer.Annotated)((*NetworkArgs)(nil))
var _ = (infer.Annotated)((*NetworkState)(nil))

Expand Down Expand Up @@ -80,7 +79,7 @@ func (v *VMInput) Annotate(a infer.Annotator) {
a.Describe(&v.Description, "The description of the virtual machine workload, optional with no restrictions")
a.Describe(&v.NodeID, "The node ID to deploy the virtual machine on, required and should match the requested resources")
a.Describe(&v.Flist, "The flist to be mounted in the virtual machine, required and should be valid. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist")
a.Describe(&v.Entrypoint, "The entry point for the flist. Example: /sbin/zinit init")
a.Describe(&v.EntryPoint, "The entry point for the flist. Example: /sbin/zinit init")
a.Describe(&v.FlistChecksum, "The checksum of the flist which should match the checksum of the given flist, optional")
a.Describe(&v.CPU, "The cpu units needed for the virtual machine. Range in [1: 32]")
a.Describe(&v.Memory, "The memory capacity for the virtual machine in MB. Min is 250 MB")
Expand Down Expand Up @@ -183,13 +182,17 @@ var _ = (infer.Annotated)((*K8sNodeInput)(nil))

func (k *KubernetesArgs) Annotate(a infer.Annotator) {
a.SetDefault(&k.SolutionType, fmt.Sprintf("kubernetes/%s", k.Master.Name))
a.SetDefault(&k.SSHKey, os.Getenv("SSH_KEY")) // for testing purposes

a.Describe(&k.Master, "Master holds the configuration of master node in the kubernetes cluster")
a.Describe(&k.Workers, "Workers is a list holding the workers configuration for the kubernetes cluster")
a.Describe(&k.NetworkName, "The name of the network, it's required and cannot exceed 50 characters. Only alphanumeric and underscores characters are supported. Network must exist")
a.Describe(&k.SolutionType, "The solution type of the cluster, displayed as project name in contract metadata")
a.Describe(&k.SSHKey, "SSH key to access the cluster nodes")
a.Describe(&k.Token, "The cluster secret token. Each node has to have this token to be part of the cluster. This token should be an alphanumeric non-empty string")
a.Describe(&k.Flist, "The flist to be mounted in the kubernetes cluster nodes. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist")
a.Describe(&k.EntryPoint, "The entry point for the flist. Example: /sbin/zinit init")
a.Describe(&k.FlistChecksum, "The checksum of the flist which should match the checksum of the given flist, optional")
}

func (k *KubernetesState) Annotate(a infer.Annotator) {
Expand All @@ -200,6 +203,23 @@ func (k *KubernetesState) Annotate(a infer.Annotator) {
}

func (k *K8sNodeInput) Annotate(a infer.Annotator) {
a.SetDefault(&k.Flist, "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist")
a.SetDefault(&k.EntryPoint, "/sbin/zinit init")

a.Describe(&k.Name, "The name of the kubernetes node, it's required and cannot exceed 50 characters. Only alphanumeric and underscores characters are supported")
a.Describe(&k.NetworkName, "The name of the network, it's required and cannot exceed 50 characters. Only alphanumeric and underscores characters are supported. Network must exist")
a.Describe(&k.Description, "The description of the kubernetes node, optional with no restrictions")
a.Describe(&k.NodeID, "The node ID to deploy the kubernetes node on, required and should match the requested resources")
a.Describe(&k.Flist, "The flist to be mounted in the kubernetes node. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist")
a.Describe(&k.EntryPoint, "The entry point for the flist. Example: /sbin/zinit init")
a.Describe(&k.FlistChecksum, "The checksum of the flist which should match the checksum of the given flist, optional")
a.Describe(&k.CPU, "The cpu units needed for the kubernetes node. Range in [1: 32]")
a.Describe(&k.Memory, "The memory capacity for the kubernetes node in MB. Min is 250 MB")
a.Describe(&k.Mycelium, "A flag to generate a random mycelium IP seed to support mycelium in the kubernetes node")
a.Describe(&k.MyceliumIPSeed, "The seed used for mycelium IP generated for the kubernetes node. It's length should be 6")
a.Describe(&k.Planetary, "A flag to enable generating a yggdrasil IP for the kubernetes node")
a.Describe(&k.PublicIP, "A flag to enable generating a public IP for the kubernetes node, public node is required for it")
a.Describe(&k.PublicIP6, "A flag to enable generating a public IPv6 for the kubernetes node, public node is required for it")
a.Describe(&k.DiskSize, "Data disk size in GBs. Must be between 1GB and 10240GBs (10TBs)")
}

Expand Down
91 changes: 43 additions & 48 deletions provider/cmd/pulumi-resource-threefold/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,102 +155,71 @@
"properties": {
"cpu": {
"type": "integer",
"description": "The cpu units needed for the virtual machine. Range in [1: 32]"
"description": "The cpu units needed for the kubernetes node. Range in [1: 32]"
},
"description": {
"type": "string",
"description": "The description of the virtual machine workload, optional with no restrictions"
"description": "The description of the kubernetes node, optional with no restrictions"
},
"disk_size": {
"type": "integer",
"description": "Data disk size in GBs. Must be between 1GB and 10240GBs (10TBs)"
},
"entrypoint": {
"entry_point": {
"type": "string",
"description": "The entry point for the flist. Example: /sbin/zinit init"
},
"env_vars": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "The environment variables to be passed to the virtual machine. Example: SSH_KEY"
"description": "The entry point for the flist. Example: /sbin/zinit init",
"default": "/sbin/zinit init"
},
"flist": {
"type": "string",
"description": "The flist to be mounted in the virtual machine, required and should be valid. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist"
"description": "The flist to be mounted in the kubernetes node. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist",
"default": "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist"
},
"flist_checksum": {
"type": "string",
"description": "The checksum of the flist which should match the checksum of the given flist, optional"
},
"gpus": {
"type": "array",
"items": {
"type": "string"
},
"description": "A list of gpu IDs to be used in the virtual machine. GPU ID format: \u003cslot\u003e/\u003cvendor\u003e/\u003cdevice\u003e. Example: 0000:28:00.0/1002/731f"
},
"memory": {
"type": "integer",
"description": "The memory capacity for the virtual machine in MB. Min is 250 MB"
},
"mounts": {
"type": "array",
"items": {
"$ref": "#/types/threefold:index:Mount"
},
"description": "A list of mounted disks or volumes"
"description": "The memory capacity for the kubernetes node in MB. Min is 250 MB"
},
"mycelium": {
"type": "boolean",
"description": "A flag to generate a random mycelium IP seed to support mycelium in the virtual machine"
"description": "A flag to generate a random mycelium IP seed to support mycelium in the kubernetes node"
},
"mycelium_ip_seed": {
"type": "string",
"description": "The seed used for mycelium IP generated for the virtual machine. It's length should be 6"
"description": "The seed used for mycelium IP generated for the kubernetes node. It's length should be 6"
},
"name": {
"type": "string",
"description": "The name of the virtual machine workload, it's required and cannot exceed 50 characters. Only alphanumeric and underscores characters are supported"
"description": "The name of the kubernetes node, it's required and cannot exceed 50 characters. Only alphanumeric and underscores characters are supported"
},
"network_name": {
"type": "string",
"description": "The name of the network, it's required and cannot exceed 50 characters. Only alphanumeric and underscores characters are supported. Network must exist"
},
"node_id": {
"$ref": "pulumi.json#/Any",
"description": "The node ID to deploy the virtual machine on, required and should match the requested resources"
"description": "The node ID to deploy the kubernetes node on, required and should match the requested resources"
},
"planetary": {
"type": "boolean",
"description": "A flag to enable generating a yggdrasil IP for the virtual machine"
"description": "A flag to enable generating a yggdrasil IP for the kubernetes node"
},
"public_ip": {
"type": "boolean",
"description": "A flag to enable generating a public IP for the virtual machine, public node is required for it"
"description": "A flag to enable generating a public IP for the kubernetes node, public node is required for it"
},
"public_ip6": {
"type": "boolean",
"description": "A flag to enable generating a public IPv6 for the virtual machine, public node is required for it"
},
"rootfs_size": {
"type": "integer",
"description": "The root fs size in GB (type SSD). Can be set as 0 to get the default minimum"
},
"zlogs": {
"type": "array",
"items": {
"$ref": "#/types/threefold:index:Zlog"
},
"description": "A list of virtual machine loggers"
"description": "A flag to enable generating a public IPv6 for the kubernetes node, public node is required for it"
}
},
"type": "object",
"required": [
"cpu",
"disk_size",
"flist",
"memory",
"name",
"network_name",
Expand Down Expand Up @@ -1083,6 +1052,18 @@
},
"threefold:index:Kubernetes": {
"properties": {
"entry_point": {
"type": "string",
"description": "The entry point for the flist. Example: /sbin/zinit init"
},
"flist": {
"type": "string",
"description": "The flist to be mounted in the kubernetes cluster nodes. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist"
},
"flist_checksum": {
"type": "string",
"description": "The checksum of the flist which should match the checksum of the given flist, optional"
},
"master": {
"$ref": "#/types/threefold:index:K8sNodeInput",
"description": "Master holds the configuration of master node in the kubernetes cluster"
Expand Down Expand Up @@ -1116,7 +1097,8 @@
},
"ssh_key": {
"type": "string",
"description": "SSH key to access the cluster nodes"
"description": "SSH key to access the cluster nodes",
"default": ""
},
"token": {
"type": "string",
Expand Down Expand Up @@ -1149,6 +1131,18 @@
"workers_computed"
],
"inputProperties": {
"entry_point": {
"type": "string",
"description": "The entry point for the flist. Example: /sbin/zinit init"
},
"flist": {
"type": "string",
"description": "The flist to be mounted in the kubernetes cluster nodes. Example: https://hub.grid.tf/tf-official-apps/base:latest.flist"
},
"flist_checksum": {
"type": "string",
"description": "The checksum of the flist which should match the checksum of the given flist, optional"
},
"master": {
"$ref": "#/types/threefold:index:K8sNodeInput",
"description": "Master holds the configuration of master node in the kubernetes cluster"
Expand All @@ -1164,7 +1158,8 @@
},
"ssh_key": {
"type": "string",
"description": "SSH key to access the cluster nodes"
"description": "SSH key to access the cluster nodes",
"default": ""
},
"token": {
"type": "string",
Expand Down
6 changes: 3 additions & 3 deletions provider/deployment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type VMInput struct {
Description string `pulumi:"description,optional"`
GPUs []zos.GPU `pulumi:"gpus,optional"`
RootfsSize int `pulumi:"rootfs_size,optional"`
Entrypoint string `pulumi:"entrypoint,optional"`
EntryPoint string `pulumi:"entrypoint,optional"`
Mounts []Mount `pulumi:"mounts,optional"`
Zlogs []Zlog `pulumi:"zlogs,optional"`
EnvVars map[string]string `pulumi:"env_vars,optional"`
Expand Down Expand Up @@ -210,7 +210,7 @@ func parseInputToDeployment(deploymentArgs DeploymentArgs) (workloads.Deployment
CPU: uint8(vm.CPU),
MemoryMB: uint64(vm.Memory),
RootfsSizeMB: uint64(vm.RootfsSize),
Entrypoint: vm.Entrypoint,
Entrypoint: vm.EntryPoint,
Mounts: mounts,
Zlogs: zlogs,
EnvVars: vm.EnvVars,
Expand Down Expand Up @@ -347,7 +347,7 @@ func parseDeploymentToState(deployment workloads.Deployment) DeploymentState {
CPU: int(vm.CPU),
Memory: int(vm.MemoryMB),
RootfsSize: int(vm.RootfsSizeMB),
Entrypoint: vm.Entrypoint,
EntryPoint: vm.Entrypoint,
Mounts: mounts,
Zlogs: zlogs,
EnvVars: vm.EnvVars,
Expand Down
2 changes: 1 addition & 1 deletion provider/deployment_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func generateInputs() (Disk, ZDBInput, VMInput, QSFSInput, DeploymentArgs) {
Description: "vm-description",
GPUs: []zos.GPU{"gpu"},
RootfsSize: 0,
Entrypoint: "entrypoint",
EntryPoint: "entrypoint",
Mounts: []Mount{{
Name: diskInput.Name,
MountPoint: fmt.Sprintf("/%s", diskInput.Name),
Expand Down
4 changes: 2 additions & 2 deletions provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/pulumi/pulumi/pkg/v3 v3.134.0
github.com/pulumi/pulumi/sdk/v3 v3.134.0
github.com/stretchr/testify v1.9.0
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17-0.20240904123303-a296d35314f5
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.16
github.com/threefoldtech/zos v0.5.6-0.20240902110349-172a0a29a6ee
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
Expand Down Expand Up @@ -172,7 +172,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240827163226-d4e15e206974 // indirect
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.16 // indirect
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.17 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/vedhavyas/go-subkey v1.0.3 // indirect
Expand Down
Loading

0 comments on commit 8289dce

Please sign in to comment.