Documentation
¶
Overview ¶
Package deployer for grid deployer
Index ¶
- Variables
- func Capacity(dl zosTypes.Deployment) (zosTypes.Capacity, error)
- func ConstructWorkloadVersions(dl zosTypes.Deployment) map[string]uint32
- func CountDeploymentPublicIPs(dl zosTypes.Deployment) (uint32, error)
- func FilterNodes(ctx context.Context, tfPlugin TFPluginClient, options types.NodeFilter, ...) ([]types.Node, error)
- func GetPublicNode(ctx context.Context, tfPlugin TFPluginClient, preferredNodes []uint32) (uint32, error)
- func GetWorkloadHashes(dl zosTypes.Deployment) (map[string]string, error)
- func HasWorkload(dl *zosTypes.Deployment, wlType string) bool
- func HashDeployment(dl zosTypes.Deployment) (string, error)
- func SameWorkloadsNames(d1 zosTypes.Deployment, d2 zosTypes.Deployment) bool
- type Deployer
- func (d *Deployer) BatchDeploy(ctx context.Context, deployments map[uint32][]zos.Deployment, ...) (map[uint32][]zos.Deployment, error)
- func (d *Deployer) Cancel(ctx context.Context, contractID uint64) error
- func (d *Deployer) Deploy(ctx context.Context, oldDeploymentIDs map[uint32]uint64, ...) (map[uint32]uint64, error)
- func (d *Deployer) GetDeployments(ctx context.Context, dls map[uint32]uint64) (map[uint32]zos.Deployment, error)
- func (d *Deployer) Validate(ctx context.Context, oldDeployments map[uint32]zos.Deployment, ...) error
- func (d *Deployer) Wait(ctx context.Context, nodeClient *client.NodeClient, deploymentID uint64, ...) error
- type DeploymentDeployer
- func (d *DeploymentDeployer) BatchDeploy(ctx context.Context, dls []*workloads.Deployment) error
- func (d *DeploymentDeployer) Cancel(ctx context.Context, dl *workloads.Deployment) error
- func (d *DeploymentDeployer) Deploy(ctx context.Context, dl *workloads.Deployment) error
- func (d *DeploymentDeployer) GenerateVersionlessDeployments(ctx context.Context, dls []*workloads.Deployment) (map[uint32][]zos.Deployment, error)
- func (d *DeploymentDeployer) Sync(ctx context.Context, dl *workloads.Deployment) error
- func (d *DeploymentDeployer) Validate(ctx context.Context, dls []*workloads.Deployment) error
- type GatewayFQDNDeployer
- func (d *GatewayFQDNDeployer) BatchDeploy(ctx context.Context, gws []*workloads.GatewayFQDNProxy) error
- func (d *GatewayFQDNDeployer) Cancel(ctx context.Context, gw *workloads.GatewayFQDNProxy) (err error)
- func (d *GatewayFQDNDeployer) Deploy(ctx context.Context, gw *workloads.GatewayFQDNProxy) error
- func (d *GatewayFQDNDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayFQDNProxy) (map[uint32]zosTypes.Deployment, error)
- func (d *GatewayFQDNDeployer) Sync(ctx context.Context, gw *workloads.GatewayFQDNProxy) error
- func (d *GatewayFQDNDeployer) Validate(ctx context.Context, gw *workloads.GatewayFQDNProxy) error
- type GatewayNameDeployer
- func (d *GatewayNameDeployer) BatchDeploy(ctx context.Context, gws []*workloads.GatewayNameProxy) error
- func (d *GatewayNameDeployer) Cancel(ctx context.Context, gw *workloads.GatewayNameProxy) (err error)
- func (d *GatewayNameDeployer) Deploy(ctx context.Context, gw *workloads.GatewayNameProxy) error
- func (d *GatewayNameDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayNameProxy) (map[uint32]zosTypes.Deployment, error)
- func (d *GatewayNameDeployer) InvalidateNameContract(ctx context.Context, gw *workloads.GatewayNameProxy) (err error)
- func (d *GatewayNameDeployer) Sync(ctx context.Context, gw *workloads.GatewayNameProxy) (err error)
- func (d *GatewayNameDeployer) Validate(ctx context.Context, gw *workloads.GatewayNameProxy) error
- type K8sDeployer
- func (d *K8sDeployer) BatchDeploy(ctx context.Context, k8sClusters []*workloads.K8sCluster) error
- func (d *K8sDeployer) Cancel(ctx context.Context, k8sCluster *workloads.K8sCluster) (err error)
- func (d *K8sDeployer) Deploy(ctx context.Context, k8sCluster *workloads.K8sCluster) error
- func (d *K8sDeployer) GenerateVersionlessDeployments(ctx context.Context, k8sCluster *workloads.K8sCluster) (map[uint32]zosTypes.Deployment, error)
- func (d *K8sDeployer) UpdateFromRemote(ctx context.Context, k8sCluster *workloads.K8sCluster) error
- func (d *K8sDeployer) Validate(ctx context.Context, k8sCluster *workloads.K8sCluster) error
- type MockDeployer
- type NetworkDeployer
- func (d *NetworkDeployer) BatchCancel(ctx context.Context, znets []workloads.Network) error
- func (d *NetworkDeployer) BatchDeploy(ctx context.Context, zNets []workloads.Network, updateMetadata ...bool) error
- func (d *NetworkDeployer) Cancel(ctx context.Context, znet workloads.Network) error
- func (d *NetworkDeployer) Deploy(ctx context.Context, znet workloads.Network) error
- func (d *NetworkDeployer) GenerateVersionlessDeployments(ctx context.Context, zNets []workloads.Network) (map[uint32][]zos.Deployment, error)
- func (d *NetworkDeployer) Validate(ctx context.Context, networks []workloads.Network) ([]workloads.Network, error)
- type PluginOpt
- func WithGraphQlURL(graphqlURLs ...string) PluginOpt
- func WithKeyType(keyType string) PluginOpt
- func WithLogs() PluginOpt
- func WithNetwork(network string) PluginOpt
- func WithProxyURL(proxyURLs ...string) PluginOpt
- func WithRMBTimeout(rmbTimeout int) PluginOpt
- func WithRelayURL(relayURLs ...string) PluginOpt
- func WithSubstrateURL(substrateURLs ...string) PluginOpt
- func WithTwinCache() PluginOpt
- type Progress
- type TFPluginClient
Examples ¶
- DeploymentDeployer.BatchDeploy
- DeploymentDeployer.Cancel
- DeploymentDeployer.Deploy
- FilterNodes
- GatewayFQDNDeployer.BatchDeploy
- GatewayFQDNDeployer.Cancel
- GatewayFQDNDeployer.Deploy
- GatewayNameDeployer.BatchDeploy
- GatewayNameDeployer.Cancel
- GatewayNameDeployer.Deploy
- K8sDeployer.BatchDeploy
- K8sDeployer.Cancel
- K8sDeployer.Deploy
- NetworkDeployer.BatchDeploy
- NetworkDeployer.Cancel
- NetworkDeployer.Deploy
- NewTFPluginClient
- TFPluginClient.BatchCancelContract
Constants ¶
This section is empty.
Variables ¶
var ( DevNetwork = "dev" QaNetwork = "qa" TestNetwork = "test" MainNetwork = "main" // SubstrateURLs are substrate urls SubstrateURLs = map[string][]string{ DevNetwork: { "wss://tfchain.dev.grid.tf/ws", "wss://tfchain.dev.grid.tf:443", "wss://tfchain.02.dev.grid.tf/ws", "wss://tfchain.02.dev.grid.tf:443", }, QaNetwork: { "wss://tfchain.qa.grid.tf/ws", "wss://tfchain.qa.grid.tf:443", "wss://tfchain.02.qa.grid.tf/ws", "wss://tfchain.02.qa.grid.tf:443", }, TestNetwork: { "wss://tfchain.test.grid.tf/ws", "wss://tfchain.test.grid.tf:443", "wss://tfchain.02.test.grid.tf/ws", "wss://tfchain.02.test.grid.tf:443", }, MainNetwork: { "wss://tfchain.grid.tf/ws", "wss://tfchain.grid.tf:443", "wss://tfchain.02.grid.tf/ws", "wss://tfchain.02.grid.tf:443", }, } // ProxyURLs are proxy urls ProxyURLs = map[string][]string{ DevNetwork: { "https://gridproxy.dev.grid.tf/", "https://gridproxy.02.dev.grid.tf/", }, TestNetwork: { "https://gridproxy.test.grid.tf/", "https://gridproxy.02.test.grid.tf/", }, QaNetwork: { "https://gridproxy.qa.grid.tf/", "https://gridproxy.02.qa.grid.tf/", }, MainNetwork: { "https://gridproxy.grid.tf/", "https://gridproxy.02.grid.tf/", }, } // GraphQlURLs for graphql urls GraphQlURLs = map[string][]string{ DevNetwork: { "https://graphql.dev.grid.tf/graphql", "https://graphql.02.dev.grid.tf/graphql", }, TestNetwork: { "https://graphql.test.grid.tf/graphql", "https://graphql.02.test.grid.tf/graphql", }, QaNetwork: { "https://graphql.qa.grid.tf/graphql", "https://graphql.02.qa.grid.tf/graphql", }, MainNetwork: { "https://graphql.grid.tf/graphql", "https://graphql.02.grid.tf/graphql", }, } // RelayURLs relay urls RelayURLs = map[string][]string{ DevNetwork: { "wss://relay.dev.grid.tf", "wss://relay.02.dev.grid.tf", }, TestNetwork: { "wss://relay.test.grid.tf", "wss://relay.02.test.grid.tf", }, QaNetwork: { "wss://relay.qa.grid.tf", "wss://relay.02.qa.grid.tf", }, MainNetwork: { "wss://relay.grid.tf", "wss://relay.02.grid.tf", }, } KycURLs = map[string]string{ DevNetwork: "https://kyc.dev.grid.tf", TestNetwork: "https://kyc.test.grid.tf", QaNetwork: "https://kyc.qa.grid.tf", MainNetwork: "https://kyc.grid.tf", } )
var ErrNoNodesMatchesResources = errors.New("could not find enough nodes with specified options")
Functions ¶
func Capacity ¶
func Capacity(dl zosTypes.Deployment) (zosTypes.Capacity, error)
Capacity returns the capacity of a deployment
func ConstructWorkloadVersions ¶
func ConstructWorkloadVersions(dl zosTypes.Deployment) map[string]uint32
ConstructWorkloadVersions returns a mapping between workload name to the workload version
func CountDeploymentPublicIPs ¶
func CountDeploymentPublicIPs(dl zosTypes.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, 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, WithNetwork(network)) if err != nil { fmt.Println(err) return } trueVal := true freeMRU := uint64(2048) freeSRU := uint64(2048) filter := types.NodeFilter{ Status: []string{"up"}, 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")
Output:
func GetPublicNode ¶
func GetPublicNode(ctx context.Context, tfPlugin TFPluginClient, preferredNodes []uint32) (uint32, error)
GetPublicNode return public node ID
func GetWorkloadHashes ¶
func GetWorkloadHashes(dl zosTypes.Deployment) (map[string]string, error)
GetWorkloadHashes returns a mapping between workload name to the workload hash
func HasWorkload ¶
func HasWorkload(dl *zosTypes.Deployment, wlType string) bool
HasWorkload checks if a deployment contains a given workload
func HashDeployment ¶
func HashDeployment(dl zosTypes.Deployment) (string, error)
HashDeployment returns deployment hash
func SameWorkloadsNames ¶
func SameWorkloadsNames(d1 zosTypes.Deployment, d2 zosTypes.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][]zos.Deployment, deploymentsSolutionProvider map[uint32][]*uint64, ) (map[uint32][]zos.Deployment, error)
BatchDeploy deploys a batch of deployments, successful deployments should have ContractID fields set
func (*Deployer) Deploy ¶
func (d *Deployer) Deploy(ctx context.Context, oldDeploymentIDs map[uint32]uint64, newDeployments map[uint32]zos.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]zos.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]zos.Deployment, newDeployments map[uint32]zos.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
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, WithNetwork(network)) if err != nil { fmt.Println(err) return } n := workloads.ZNet{ Name: "network", Description: "network for testing", Nodes: []uint32{nodeID}, IPRange: zosTypes.IPNet{IPNet: net.IPNet{ IP: net.IPv4(10, 1, 0, 0), Mask: net.CIDRMask(16, 32), }}, AddWGAccess: false, } vm1 := workloads.VM{ Name: "vm1", NodeID: nodeID, Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", CPU: 2, Planetary: true, MemoryMB: 1024, Entrypoint: "/sbin/zinit init", EnvVars: map[string]string{"SSH_KEY": "<ssh key goes here>"}, NetworkName: n.Name, } vm2 := workloads.VM{ Name: "vm2", NodeID: nodeID, Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", CPU: 2, Planetary: true, MemoryMB: 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, nil, nil) d2 := workloads.NewDeployment("vm2deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm2}, nil, nil, 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")
Output:
func (*DeploymentDeployer) Cancel ¶
func (d *DeploymentDeployer) Cancel(ctx context.Context, dl *workloads.Deployment) error
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, WithNetwork(network)) if err != nil { fmt.Println(err) return } // dl should be a valid and existing deployment name deploymentName := "vmdeployment" dl, err := tfPluginClient.State.LoadDeploymentFromGrid(context.Background(), 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")
Output:
func (*DeploymentDeployer) Deploy ¶
func (d *DeploymentDeployer) Deploy(ctx context.Context, dl *workloads.Deployment) error
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, WithNetwork(network)) if err != nil { fmt.Println(err) return } n := workloads.ZNet{ Name: "network", Description: "network for testing", Nodes: []uint32{nodeID}, IPRange: zosTypes.IPNet{IPNet: net.IPNet{ IP: net.IPv4(10, 1, 0, 0), Mask: net.CIDRMask(16, 32), }}, AddWGAccess: false, } vm := workloads.VM{ Name: "vm", NodeID: nodeID, Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", CPU: 2, Planetary: true, MemoryMB: 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, nil, nil) err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl) if err != nil { fmt.Println(err) return } fmt.Println("deployment is done successfully")
Output:
func (*DeploymentDeployer) GenerateVersionlessDeployments ¶
func (d *DeploymentDeployer) GenerateVersionlessDeployments(ctx context.Context, dls []*workloads.Deployment) (map[uint32][]zos.Deployment, error)
GenerateVersionlessDeployments generates a new deployment without a version
func (*DeploymentDeployer) Sync ¶
func (d *DeploymentDeployer) Sync(ctx context.Context, dl *workloads.Deployment) error
Sync syncs the deployments // TODO: remove
func (*DeploymentDeployer) Validate ¶
func (d *DeploymentDeployer) Validate(ctx context.Context, dls []*workloads.Deployment) error
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, WithNetwork(network)) 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")
Output:
func (*GatewayFQDNDeployer) Cancel ¶
func (d *GatewayFQDNDeployer) Cancel(ctx context.Context, gw *workloads.GatewayFQDNProxy) (err error)
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, WithNetwork(network)) 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(context.Background(), 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")
Output:
func (*GatewayFQDNDeployer) Deploy ¶
func (d *GatewayFQDNDeployer) Deploy(ctx context.Context, gw *workloads.GatewayFQDNProxy) error
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, WithNetwork(network)) 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")
Output:
func (*GatewayFQDNDeployer) GenerateVersionlessDeployments ¶
func (d *GatewayFQDNDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayFQDNProxy) (map[uint32]zosTypes.Deployment, error)
GenerateVersionlessDeployments generates deployments for gatewayFqdn deployer without versions
func (*GatewayFQDNDeployer) Sync ¶
func (d *GatewayFQDNDeployer) Sync(ctx context.Context, gw *workloads.GatewayFQDNProxy) error
Sync syncs the gateway deployments
func (*GatewayFQDNDeployer) Validate ¶
func (d *GatewayFQDNDeployer) Validate(ctx context.Context, gw *workloads.GatewayFQDNProxy) error
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, WithNetwork(network)) 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")
Output:
func (*GatewayNameDeployer) Cancel ¶
func (d *GatewayNameDeployer) Cancel(ctx context.Context, gw *workloads.GatewayNameProxy) (err error)
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, WithNetwork(network)) 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(context.Background(), 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")
Output:
func (*GatewayNameDeployer) Deploy ¶
func (d *GatewayNameDeployer) Deploy(ctx context.Context, gw *workloads.GatewayNameProxy) error
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, WithNetwork(network)) 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")
Output:
func (*GatewayNameDeployer) GenerateVersionlessDeployments ¶
func (d *GatewayNameDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayNameProxy) (map[uint32]zosTypes.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 ¶
func (d *GatewayNameDeployer) Sync(ctx context.Context, gw *workloads.GatewayNameProxy) (err error)
Sync syncs the gateway deployments
func (*GatewayNameDeployer) Validate ¶
func (d *GatewayNameDeployer) Validate(ctx context.Context, gw *workloads.GatewayNameProxy) error
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 flistCheckSum, err := workloads.GetFlistChecksum(workloads.K8sFlist) if err != nil { fmt.Println(err) return } tfPluginClient, err := NewTFPluginClient(mnemonic, WithNetwork(network)) if err != nil { fmt.Println(err) return } n := workloads.ZNet{ Name: "network", Description: "network for testing", Nodes: []uint32{nodeID}, IPRange: zosTypes.IPNet{IPNet: net.IPNet{ IP: net.IPv4(10, 1, 0, 0), Mask: net.CIDRMask(16, 32), }}, AddWGAccess: false, } master := workloads.K8sNode{ VM: &workloads.VM{ Name: "mr1", NodeID: nodeID, CPU: 2, MemoryMB: 1024, }, DiskSizeGB: 5, } worker := workloads.K8sNode{ VM: &workloads.VM{ Name: "worker1", NodeID: nodeID, CPU: 2, MemoryMB: 1024, }, DiskSizeGB: 5, } cluster1 := workloads.K8sCluster{ Master: &master, Workers: []workloads.K8sNode{worker}, Token: "tokens", SSHKey: "<ssh key goes here>", NetworkName: n.Name, Flist: workloads.K8sFlist, FlistChecksum: flistCheckSum, 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")
Output:
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, WithNetwork(network)) if err != nil { fmt.Println(err) return } // should be a valid and existing k8s cluster deployment name deploymentName := "K8sForTesting" cluster, err := tfPluginClient.State.LoadK8sFromGrid(context.Background(), []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")
Output:
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 flistCheckSum, err := workloads.GetFlistChecksum(workloads.K8sFlist) if err != nil { fmt.Println(err) return } tfPluginClient, err := NewTFPluginClient(mnemonic, WithNetwork(network)) if err != nil { fmt.Println(err) return } n := workloads.ZNet{ Name: "network", Description: "network for testing", Nodes: []uint32{nodeID}, IPRange: zosTypes.IPNet{IPNet: net.IPNet{ IP: net.IPv4(10, 1, 0, 0), Mask: net.CIDRMask(16, 32), }}, AddWGAccess: false, } master := workloads.K8sNode{ VM: &workloads.VM{ Name: "K8sForTesting", NodeID: nodeID, CPU: 2, MemoryMB: 1024, }, DiskSizeGB: 5, } worker := workloads.K8sNode{ VM: &workloads.VM{ Name: "worker1", NodeID: nodeID, CPU: 2, MemoryMB: 1024, }, DiskSizeGB: 5, } cluster := workloads.K8sCluster{ Master: &master, Workers: []workloads.K8sNode{worker}, Token: "tokens", SSHKey: "<ssh key goes here>", NetworkName: n.Name, Flist: workloads.K8sFlist, FlistChecksum: flistCheckSum, 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")
Output:
func (*K8sDeployer) GenerateVersionlessDeployments ¶
func (d *K8sDeployer) GenerateVersionlessDeployments(ctx context.Context, k8sCluster *workloads.K8sCluster) (map[uint32]zosTypes.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]zos.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]zos.Deployment, error) BatchDeploy(ctx context.Context, deployments map[uint32][]zos.Deployment, deploymentsSolutionProvider map[uint32][]*uint64, ) (map[uint32][]zos.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) BatchCancel ¶ added in v0.14.0
BatchCancel cancels all contracts for given networks. if one contracts failed all networks will not be canceled and state won't be updated.
func (*NetworkDeployer) BatchDeploy ¶
func (d *NetworkDeployer) BatchDeploy(ctx context.Context, zNets []workloads.Network, updateMetadata ...bool) 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, WithNetwork(network)) if err != nil { fmt.Println(err) return } n1 := workloads.ZNet{ Name: "network1", Description: "network for testing", Nodes: []uint32{nodeID}, IPRange: zosTypes.IPNet{IPNet: 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: zosTypes.IPNet{IPNet: net.IPNet{ IP: net.IPv4(10, 1, 0, 0), Mask: net.CIDRMask(16, 32), }}, AddWGAccess: false, } err = tfPluginClient.NetworkDeployer.BatchDeploy(context.Background(), []workloads.Network{&n1, &n2}) if err != nil { fmt.Println(err) return } fmt.Println("batch deployment is done successfully")
Output:
func (*NetworkDeployer) Cancel ¶
Cancel cancels all the deployments
Example ¶
const mnemonic = "<mnemonics goes here>" const network = "<dev, test, qa, main>" tfPluginClient, err := NewTFPluginClient(mnemonic, WithNetwork(network)) if err != nil { fmt.Println(err) return } // should be a valid and existing network name networkName := "network" n, err := tfPluginClient.State.LoadNetworkFromGrid(context.Background(), 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")
Output:
func (*NetworkDeployer) Deploy ¶
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, WithNetwork(network), WithRMBTimeout(10)) if err != nil { fmt.Println(err) return } n := workloads.ZNet{ Name: "network", Description: "network for testing", Nodes: []uint32{nodeID}, IPRange: zosTypes.IPNet{IPNet: 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")
Output:
func (*NetworkDeployer) GenerateVersionlessDeployments ¶
func (d *NetworkDeployer) GenerateVersionlessDeployments(ctx context.Context, zNets []workloads.Network) (map[uint32][]zos.Deployment, error)
GenerateVersionlessDeployments generates deployments for network deployer without versions.
type PluginOpt ¶ added in v0.14.8
type PluginOpt func(*pluginCfg)
func WithGraphQlURL ¶ added in v0.15.12
func WithKeyType ¶ added in v0.14.8
func WithNetwork ¶ added in v0.14.8
func WithProxyURL ¶ added in v0.14.8
func WithRMBTimeout ¶ added in v0.14.8
func WithRelayURL ¶ added in v0.14.8
func WithSubstrateURL ¶ added in v0.14.8
func WithTwinCache ¶ added in v0.14.8
func WithTwinCache() PluginOpt
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, opts ...PluginOpt, ) (TFPluginClient, error)
NewTFPluginClient generates a new tf plugin client
Example ¶
mnemonic := "<mnemonics goes here>" network := "<dev, test, qa, main>" tfPluginClient, err := NewTFPluginClient(mnemonic, WithNetwork(network)) if err != nil { fmt.Println(err) return } fmt.Println("tfPluginClient is created successfully ", tfPluginClient)
Output:
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, WithNetwork(network)) 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")
Output:
func (*TFPluginClient) CancelByProjectName ¶
func (t *TFPluginClient) CancelByProjectName(projectName string, noGateways ...bool) error
CancelByProjectName cancels a deployed project
func (*TFPluginClient) Close ¶
func (t *TFPluginClient) Close()
Close closes the relay connection and the substrate connection