deployer

package
v0.13.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 40 Imported by: 8

Documentation

Overview

Package deployer for grid deployer

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// SubstrateURLs are substrate urls
	SubstrateURLs = map[string]string{
		"dev":  "wss://tfchain.dev.grid.tf/ws",
		"test": "wss://tfchain.test.grid.tf/ws",
		"qa":   "wss://tfchain.qa.grid.tf/ws",
		"main": "wss://tfchain.grid.tf/ws",
	}
	// RMBProxyURLs are rmb proxy urls
	RMBProxyURLs = map[string]string{
		"dev":  "https://gridproxy.dev.grid.tf/",
		"test": "https://gridproxy.test.grid.tf/",
		"qa":   "https://gridproxy.qa.grid.tf/",
		"main": "https://gridproxy.grid.tf/",
	}
	// GraphQlURLs urls
	GraphQlURLs = map[string]string{
		"dev":  "https://graphql.dev.grid.tf/graphql",
		"test": "https://graphql.test.grid.tf/graphql",
		"qa":   "https://graphql.qa.grid.tf/graphql",
		"main": "https://graphql.grid.tf/graphql",
	}
	// RelayURLS relay urls
	RelayURLS = map[string]string{
		"dev":  "wss://relay.dev.grid.tf",
		"test": "wss://relay.test.grid.tf",
		"qa":   "wss://relay.qa.grid.tf",
		"main": "wss://relay.grid.tf",
	}
)

Functions

func Capacity

Capacity returns the capacity of a deployment

func ConstructWorkloadVersions

func ConstructWorkloadVersions(dl gridtypes.Deployment) map[string]uint32

ConstructWorkloadVersions returns a mapping between workload name to the workload version

func CountDeploymentPublicIPs

func CountDeploymentPublicIPs(dl gridtypes.Deployment) (uint32, error)

CountDeploymentPublicIPs counts the public IPs of a deployment

func FilterNodes

func FilterNodes(ctx context.Context, tfPlugin TFPluginClient, options types.NodeFilter, ssdDisks, hddDisks []uint64, rootfs []uint64, optionalLimit ...uint64) ([]types.Node, error)

FilterNodes filters nodes using proxy

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

trueVal := true
statusUp := "up"
freeMRU := uint64(2048)
freeSRU := uint64(2048)

filter := types.NodeFilter{
	Status:  &statusUp,
	IPv4:    &trueVal,
	FreeMRU: &freeMRU,
	FreeSRU: &freeSRU,
	FarmIDs: []uint64{uint64(1)},
}

_, err = FilterNodes(context.Background(), tfPluginClient, filter, []uint64{freeSRU}, nil, nil)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("nodes filtered successfully")

func GetPublicNode

func GetPublicNode(ctx context.Context, tfPlugin TFPluginClient, preferredNodes []uint32) (uint32, error)

GetPublicNode return public node ID

func GetWorkloadHashes

func GetWorkloadHashes(dl gridtypes.Deployment) (map[string]string, error)

GetWorkloadHashes returns a mapping between workload name to the workload hash

func HasWorkload

func HasWorkload(dl *gridtypes.Deployment, wlType gridtypes.WorkloadType) bool

HasWorkload checks if a deployment contains a given workload

func HashDeployment

func HashDeployment(dl gridtypes.Deployment) (string, error)

HashDeployment returns deployment hash

func SameWorkloadsNames

func SameWorkloadsNames(d1 gridtypes.Deployment, d2 gridtypes.Deployment) bool

SameWorkloadsNames compares names of 2 deployments' workloads

Types

type Deployer

type Deployer struct {
	// contains filtered or unexported fields
}

Deployer to be used for any deployer

func NewDeployer

func NewDeployer(
	tfPluginClient TFPluginClient,
	revertOnFailure bool,
) Deployer

NewDeployer returns a new deployer

func (*Deployer) BatchDeploy

func (d *Deployer) BatchDeploy(ctx context.Context, deployments map[uint32][]gridtypes.Deployment, deploymentsSolutionProvider map[uint32][]*uint64) (map[uint32][]gridtypes.Deployment, error)

BatchDeploy deploys a batch of deployments, successful deployments should have ContractID fields set

func (*Deployer) Cancel

func (d *Deployer) Cancel(ctx context.Context,
	contractID uint64,
) error

Cancel cancels an old deployment not given in the new deployments

func (*Deployer) Deploy

func (d *Deployer) Deploy(ctx context.Context,
	oldDeploymentIDs map[uint32]uint64,
	newDeployments map[uint32]gridtypes.Deployment,
	newDeploymentSolutionProvider map[uint32]*uint64,
) (map[uint32]uint64, error)

Deploy deploys or updates a new deployment given the old deployments' IDs

func (*Deployer) GetDeployments

func (d *Deployer) GetDeployments(ctx context.Context, dls map[uint32]uint64) (map[uint32]gridtypes.Deployment, error)

GetDeployments returns deployments from a map of nodes IDs and deployments IDs

func (*Deployer) Validate

func (d *Deployer) Validate(ctx context.Context, oldDeployments map[uint32]gridtypes.Deployment, newDeployments map[uint32]gridtypes.Deployment) error

Validate is a best effort validation. it returns an error if it's very sure there's a problem

  • validates old deployments nodes (for update cases) and new deployments nodes
  • validates nodes' farm
  • checks free public ips
  • checks free nodes capacity
  • checks PublicConfig Ipv4 for fqdn gateway
  • checks PublicConfig domain for name gateway

errors that may arise because of dead nodes are ignored. if a real error dodges the validation, it'll be fail anyway in the deploying phase

func (*Deployer) Wait

func (d *Deployer) Wait(
	ctx context.Context,
	nodeClient *client.NodeClient,
	deploymentID uint64,
	workloadVersions map[string]uint32,
) error

Wait waits for a deployment to be deployed on node

type DeploymentDeployer

type DeploymentDeployer struct {
	// contains filtered or unexported fields
}

DeploymentDeployer for deploying a deployment

func NewDeploymentDeployer

func NewDeploymentDeployer(tfPluginClient *TFPluginClient) DeploymentDeployer

NewDeploymentDeployer generates a new deployer for a deployment

func (*DeploymentDeployer) BatchDeploy

func (d *DeploymentDeployer) BatchDeploy(ctx context.Context, dls []*workloads.Deployment) error

BatchDeploy deploys multiple deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

n := workloads.ZNet{
	Name:        "network",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}

vm1 := workloads.VM{
	Name:        "vm1",
	Flist:       "https://hub.grid.tf/tf-official-apps/base:latest.flist",
	CPU:         2,
	Planetary:   true,
	Memory:      1024,
	Entrypoint:  "/sbin/zinit init",
	EnvVars:     map[string]string{"SSH_KEY": "<ssh key goes here>"},
	NetworkName: n.Name,
}
vm2 := workloads.VM{
	Name:        "vm2",
	Flist:       "https://hub.grid.tf/tf-official-apps/base:latest.flist",
	CPU:         2,
	Planetary:   true,
	Memory:      1024,
	Entrypoint:  "/sbin/zinit init",
	EnvVars:     map[string]string{"SSH_KEY": "<ssh key goes here>"},
	NetworkName: n.Name,
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &n)
if err != nil {
	fmt.Println(err)
	return
}

d1 := workloads.NewDeployment("vm1deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm1}, nil)
d2 := workloads.NewDeployment("vm2deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm2}, nil)
err = tfPluginClient.DeploymentDeployer.BatchDeploy(context.Background(), []*workloads.Deployment{&d1, &d2})
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("batch deployment is done successfully")

func (*DeploymentDeployer) Cancel

Cancel cancels deployments

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

// dl should be a valid and existing deployment name
deploymentName := "vmdeployment"
dl, err := tfPluginClient.State.LoadDeploymentFromGrid(nodeID, deploymentName)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.DeploymentDeployer.Cancel(context.Background(), &dl)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("deployment is canceled successfully")

func (*DeploymentDeployer) Deploy

Deploy deploys a new deployment

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

n := workloads.ZNet{
	Name:        "network",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}

vm := workloads.VM{
	Name:        "vm",
	Flist:       "https://hub.grid.tf/tf-official-apps/base:latest.flist",
	CPU:         2,
	Planetary:   true,
	Memory:      1024,
	Entrypoint:  "/sbin/zinit init",
	EnvVars:     map[string]string{"SSH_KEY": "<ssh key goes here>"},
	NetworkName: n.Name,
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &n)
if err != nil {
	fmt.Println(err)
	return
}

dl := workloads.NewDeployment("vmdeployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm}, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("deployment is done successfully")

func (*DeploymentDeployer) GenerateVersionlessDeployments

func (d *DeploymentDeployer) GenerateVersionlessDeployments(ctx context.Context, dl *workloads.Deployment, usedHosts []byte) (map[uint32]gridtypes.Deployment, []byte, error)

GenerateVersionlessDeployments generates a new deployment without a version

func (*DeploymentDeployer) Sync

Sync syncs the deployments

func (*DeploymentDeployer) Validate

Validate validates a deployment deployer

type GatewayFQDNDeployer

type GatewayFQDNDeployer struct {
	// contains filtered or unexported fields
}

GatewayFQDNDeployer for deploying a GatewayFqdn

func NewGatewayFqdnDeployer

func NewGatewayFqdnDeployer(tfPluginClient *TFPluginClient) GatewayFQDNDeployer

NewGatewayFqdnDeployer generates new gateway fqdn deployer

func (*GatewayFQDNDeployer) BatchDeploy

func (d *GatewayFQDNDeployer) BatchDeploy(ctx context.Context, gws []*workloads.GatewayFQDNProxy) error

BatchDeploy deploys multiple deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}
g1 := workloads.GatewayFQDNProxy{
	NodeID:         nodeID,
	Name:           "test1",
	TLSPassthrough: false,
	Backends:       []zos.Backend{"http://1.1.1.1"},
	FQDN:           "test1.com",
}
g2 := workloads.GatewayFQDNProxy{
	NodeID:         nodeID,
	Name:           "test2",
	TLSPassthrough: false,
	Backends:       []zos.Backend{"http://2.2.2.2"},
	FQDN:           "test2.com",
}

err = tfPluginClient.GatewayFQDNDeployer.BatchDeploy(context.Background(), []*workloads.GatewayFQDNProxy{&g1, &g2})
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("batch deployment is done successfully")

func (*GatewayFQDNDeployer) Cancel

Cancel cancels a gateway deployment

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

// should be a valid and existing name and deploymentName
name := "test1.com"
deploymentName := "test1"
g, err := tfPluginClient.State.LoadGatewayFQDNFromGrid(nodeID, name, deploymentName)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.GatewayFQDNDeployer.Cancel(context.Background(), &g)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("deployment is canceled successfully")

func (*GatewayFQDNDeployer) Deploy

Deploy deploys the GatewayFQDN deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}
g := workloads.GatewayFQDNProxy{
	NodeID:         nodeID,
	Name:           "test1",
	TLSPassthrough: false,
	Backends:       []zos.Backend{"http://1.1.1.1"},
	FQDN:           "name.com",
}

err = tfPluginClient.GatewayFQDNDeployer.Deploy(context.Background(), &g)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("deployment is done successfully")

func (*GatewayFQDNDeployer) GenerateVersionlessDeployments

func (d *GatewayFQDNDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayFQDNProxy) (map[uint32]gridtypes.Deployment, error)

GenerateVersionlessDeployments generates deployments for gatewayFqdn deployer without versions

func (*GatewayFQDNDeployer) Sync

Sync syncs the gateway deployments

func (*GatewayFQDNDeployer) Validate

Validate validates gateway FQDN deployer

type GatewayNameDeployer

type GatewayNameDeployer struct {
	// contains filtered or unexported fields
}

GatewayNameDeployer for deploying a GatewayName

func NewGatewayNameDeployer

func NewGatewayNameDeployer(tfPluginClient *TFPluginClient) GatewayNameDeployer

NewGatewayNameDeployer generates new gateway name deployer

func (*GatewayNameDeployer) BatchDeploy

func (d *GatewayNameDeployer) BatchDeploy(ctx context.Context, gws []*workloads.GatewayNameProxy) error

BatchDeploy deploys multiple deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}
g1 := workloads.GatewayNameProxy{
	NodeID:         nodeID,
	Name:           "test1",
	TLSPassthrough: false,
	Backends:       []zos.Backend{"http://1.1.1.1"},
	FQDN:           "test1.com",
}
g2 := workloads.GatewayNameProxy{
	NodeID:         nodeID,
	Name:           "test2",
	TLSPassthrough: false,
	Backends:       []zos.Backend{"http://2.2.2.2"},
	FQDN:           "test2.com",
}

err = tfPluginClient.GatewayNameDeployer.BatchDeploy(context.Background(), []*workloads.GatewayNameProxy{&g1, &g2})
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("batch deployment is done successfully")

func (*GatewayNameDeployer) Cancel

Cancel cancels the gatewayName deployment

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

// should be a valid and existing name and deploymentName
name := "test.com"
deploymentName := "test"
g, err := tfPluginClient.State.LoadGatewayNameFromGrid(nodeID, name, deploymentName)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.GatewayNameDeployer.Cancel(context.Background(), &g)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("deployment is canceled successfully")

func (*GatewayNameDeployer) Deploy

Deploy deploys the GatewayName deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}
g := workloads.GatewayNameProxy{
	NodeID:         nodeID,
	Name:           "test",
	TLSPassthrough: false,
	Backends:       []zos.Backend{"http://1.1.1.1"},
	FQDN:           "test.com",
}

err = tfPluginClient.GatewayNameDeployer.Deploy(context.Background(), &g)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("deployment is done successfully")

func (*GatewayNameDeployer) GenerateVersionlessDeployments

func (d *GatewayNameDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayNameProxy) (map[uint32]gridtypes.Deployment, error)

GenerateVersionlessDeployments generates deployments for gateway name deployer without versions

func (*GatewayNameDeployer) InvalidateNameContract

func (d *GatewayNameDeployer) InvalidateNameContract(ctx context.Context, gw *workloads.GatewayNameProxy) (err error)

InvalidateNameContract invalidates name contract

func (*GatewayNameDeployer) Sync

Sync syncs the gateway deployments

func (*GatewayNameDeployer) Validate

Validate validates gatewayName deployer

type K8sDeployer

type K8sDeployer struct {
	// contains filtered or unexported fields
}

K8sDeployer for deploying k8s

func NewK8sDeployer

func NewK8sDeployer(tfPluginClient *TFPluginClient) K8sDeployer

NewK8sDeployer generates new K8s Deployer

func (*K8sDeployer) BatchDeploy

func (d *K8sDeployer) BatchDeploy(ctx context.Context, k8sClusters []*workloads.K8sCluster) error

BatchDeploy deploys multiple clusters using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

const flist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist"
flistCheckSum, err := workloads.GetFlistChecksum(flist)
if err != nil {
	fmt.Println(err)
	return
}

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

n := workloads.ZNet{
	Name:        "network",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}

master := workloads.K8sNode{
	Name:          "mr1",
	Node:          nodeID,
	Flist:         flist,
	FlistChecksum: flistCheckSum,
	CPU:           2,
	DiskSize:      5,
	Memory:        1024,
}

worker := workloads.K8sNode{
	Name:          "worker1",
	Node:          nodeID,
	Flist:         flist,
	FlistChecksum: flistCheckSum,
	DiskSize:      5,
	CPU:           2,
	Memory:        1024,
}

cluster1 := workloads.K8sCluster{
	Master:       &master,
	Workers:      []workloads.K8sNode{worker},
	Token:        "tokens",
	SSHKey:       "<ssh key goes here>",
	NetworkName:  n.Name,
	NodesIPRange: make(map[uint32]gridtypes.IPNet),
}

master.Name = "mr2"
worker.Name = "worker2"
cluster2 := workloads.K8sCluster{
	Master:       &master,
	Workers:      []workloads.K8sNode{worker},
	Token:        "tokens",
	SSHKey:       "<ssh key goes here>",
	NetworkName:  n.Name,
	NodesIPRange: make(map[uint32]gridtypes.IPNet),
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &n)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.K8sDeployer.BatchDeploy(context.Background(), []*workloads.K8sCluster{&cluster1, &cluster2})
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("batch deployment is done successfully")

func (*K8sDeployer) Cancel

func (d *K8sDeployer) Cancel(ctx context.Context, k8sCluster *workloads.K8sCluster) (err error)

Cancel cancels a k8s cluster deployment

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

// should be a valid and existing k8s cluster deployment name
deploymentName := "K8sForTesting"
cluster, err := tfPluginClient.State.LoadK8sFromGrid([]uint32{nodeID}, deploymentName)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.K8sDeployer.Cancel(context.Background(), &cluster)
if err != nil {
	fmt.Println(err)
}
fmt.Println("deployment is canceled successfully")

func (*K8sDeployer) Deploy

func (d *K8sDeployer) Deploy(ctx context.Context, k8sCluster *workloads.K8sCluster) error

Deploy deploys a k8s cluster deployment

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

const flist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist"
flistCheckSum, err := workloads.GetFlistChecksum(flist)
if err != nil {
	fmt.Println(err)
	return
}

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

n := workloads.ZNet{
	Name:        "network",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}

master := workloads.K8sNode{
	Name:          "K8sForTesting",
	Node:          nodeID,
	Flist:         flist,
	FlistChecksum: flistCheckSum,
	CPU:           2,
	DiskSize:      5,
	Memory:        1024,
}

worker := workloads.K8sNode{
	Name:          "worker1",
	Node:          nodeID,
	Flist:         flist,
	FlistChecksum: flistCheckSum,
	DiskSize:      5,
	CPU:           2,
	Memory:        1024,
}

cluster := workloads.K8sCluster{
	Master:       &master,
	Workers:      []workloads.K8sNode{worker},
	Token:        "tokens",
	SSHKey:       "<ssh key goes here>",
	NetworkName:  n.Name,
	NodesIPRange: make(map[uint32]gridtypes.IPNet),
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &n)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.K8sDeployer.Deploy(context.Background(), &cluster)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("deployment done successfully")

func (*K8sDeployer) GenerateVersionlessDeployments

func (d *K8sDeployer) GenerateVersionlessDeployments(ctx context.Context, k8sCluster *workloads.K8sCluster) (map[uint32]gridtypes.Deployment, error)

GenerateVersionlessDeployments generates a new deployment without a version

func (*K8sDeployer) UpdateFromRemote

func (d *K8sDeployer) UpdateFromRemote(ctx context.Context, k8sCluster *workloads.K8sCluster) error

UpdateFromRemote update a k8s cluster

func (*K8sDeployer) Validate

func (d *K8sDeployer) Validate(ctx context.Context, k8sCluster *workloads.K8sCluster) error

Validate validates K8s deployer

type MockDeployer

type MockDeployer interface {
	Deploy(ctx context.Context,
		oldDeploymentIDs map[uint32]uint64,
		newDeployments map[uint32]gridtypes.Deployment,
		newDeploymentSolutionProvider map[uint32]*uint64,
	) (map[uint32]uint64, error)

	Cancel(ctx context.Context,
		contractID uint64,
	) error

	GetDeployments(ctx context.Context, dls map[uint32]uint64) (map[uint32]gridtypes.Deployment, error)
	BatchDeploy(ctx context.Context,
		deployments map[uint32][]gridtypes.Deployment,
		deploymentsSolutionProvider map[uint32][]*uint64,
	) (map[uint32][]gridtypes.Deployment, error)
}

MockDeployer to be used for any deployer in mock testing

type NetworkDeployer

type NetworkDeployer struct {
	// contains filtered or unexported fields
}

NetworkDeployer struct

func NewNetworkDeployer

func NewNetworkDeployer(tfPluginClient *TFPluginClient) NetworkDeployer

NewNetworkDeployer generates a new network deployer

func (*NetworkDeployer) BatchDeploy

func (d *NetworkDeployer) BatchDeploy(ctx context.Context, znets []*workloads.ZNet) error

BatchDeploy deploys multiple network deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

n1 := workloads.ZNet{
	Name:        "network1",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}
n2 := workloads.ZNet{
	Name:        "network2",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}

err = tfPluginClient.NetworkDeployer.BatchDeploy(context.Background(), []*workloads.ZNet{&n1, &n2})
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("batch deployment is done successfully")

func (*NetworkDeployer) Cancel

func (d *NetworkDeployer) Cancel(ctx context.Context, znet *workloads.ZNet) error

Cancel cancels all the deployments

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

// should be a valid and existing network name
networkName := "network"
n, err := tfPluginClient.State.LoadNetworkFromGrid(networkName)
if err != nil {
	fmt.Println(err)
	return
}

err = tfPluginClient.NetworkDeployer.Cancel(context.Background(), &n)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("deployment is canceled successfully")

func (*NetworkDeployer) Deploy

func (d *NetworkDeployer) Deploy(ctx context.Context, znet *workloads.ZNet) error

Deploy deploys the network deployments using the deployer

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"
const nodeID = 11 // use any node with status up, use ExampleFilterNodes to get valid nodeID

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

n := workloads.ZNet{
	Name:        "network",
	Description: "network for testing",
	Nodes:       []uint32{nodeID},
	IPRange: gridtypes.NewIPNet(net.IPNet{
		IP:   net.IPv4(10, 1, 0, 0),
		Mask: net.CIDRMask(16, 32),
	}),
	AddWGAccess: false,
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &n)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("deployment is done successfully")

func (*NetworkDeployer) GenerateVersionlessDeployments

func (d *NetworkDeployer) GenerateVersionlessDeployments(ctx context.Context, znet *workloads.ZNet) (map[uint32]gridtypes.Deployment, error)

GenerateVersionlessDeployments generates deployments for network deployer without versions

func (*NetworkDeployer) InvalidateBrokenAttributes

func (d *NetworkDeployer) InvalidateBrokenAttributes(znet *workloads.ZNet) error

InvalidateBrokenAttributes removes outdated attrs and deleted contracts

func (*NetworkDeployer) ReadNodesConfig

func (d *NetworkDeployer) ReadNodesConfig(ctx context.Context, znet *workloads.ZNet) error

ReadNodesConfig reads the configuration of a network

func (*NetworkDeployer) Validate

func (d *NetworkDeployer) Validate(ctx context.Context, znet *workloads.ZNet) error

Validate validates a network deployer

type Progress

type Progress struct {
	// contains filtered or unexported fields
}

Progress struct for checking progress

type TFPluginClient

type TFPluginClient struct {
	TwinID uint32

	Identity substrate.Identity

	RMBTimeout time.Duration

	// network
	Network string

	// clients
	GridProxyClient proxy.Client
	RMB             rmb.Client
	SubstrateConn   subi.SubstrateExt
	NcPool          client.NodeClientGetter

	// deployers
	DeploymentDeployer  DeploymentDeployer
	NetworkDeployer     NetworkDeployer
	GatewayFQDNDeployer GatewayFQDNDeployer
	GatewayNameDeployer GatewayNameDeployer
	K8sDeployer         K8sDeployer

	// state
	State *state.State

	ContractsGetter graphql.ContractsGetter

	// calculator
	Calculator calculator.Calculator
	// contains filtered or unexported fields
}

TFPluginClient is a Threefold plugin client

func NewTFPluginClient

func NewTFPluginClient(
	mnemonicOrSeed string,
	keyType string,
	network string,
	substrateURL string,
	relayURL string,
	rmbProxyURL string,
	rmbTimeout int,
	showLogs bool,
) (TFPluginClient, error)

NewTFPluginClient generates a new tf plugin client

Example
mnemonic := "<mnemonics goes here>"
network := "<dev, test, qa, main>"

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("tfPluginClient is created successfully ", tfPluginClient)

func (*TFPluginClient) BatchCancelContract

func (t *TFPluginClient) BatchCancelContract(contracts []uint64) error

BatchCancelContract to cancel a batch of contracts

Example
const mnemonic = "<mnemonics goes here>"
const network = "<dev, test, qa, main>"

tfPluginClient, err := NewTFPluginClient(mnemonic, "sr25519", network, "", "", "", 0, false)
if err != nil {
	fmt.Println(err)
	return
}

// list of contracts ids
contracts := []uint64{}
err = tfPluginClient.BatchCancelContract(contracts)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("all contracts were deleted successfully")

func (*TFPluginClient) CancelByProjectName

func (t *TFPluginClient) CancelByProjectName(projectName string) error

CancelByProjectName cancels a deployed project

func (*TFPluginClient) Close

func (t *TFPluginClient) Close()

Close closes the relay connection and the substrate connection

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL