Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get contract metadata if deployment metadata is missing #1074

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ linters:
- gofmt
- govet
- ineffassign
- megacheck
- misspell
- unconvert
enable-all: false
Expand Down
4 changes: 2 additions & 2 deletions grid-client/deployer/tf_plugin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ func NewTFPluginClient(
tfPluginClient.K8sDeployer = NewK8sDeployer(&tfPluginClient)
tfPluginClient.GatewayNameDeployer = NewGatewayNameDeployer(&tfPluginClient)

tfPluginClient.State = state.NewState(tfPluginClient.NcPool, tfPluginClient.SubstrateConn)

graphqlURL := GraphQlURLs[cfg.network]
tfPluginClient.graphQl, err = graphql.NewGraphQl(graphqlURL)
if err != nil {
Expand All @@ -343,6 +341,8 @@ func NewTFPluginClient(

tfPluginClient.ContractsGetter = graphql.NewContractsGetter(tfPluginClient.TwinID, tfPluginClient.graphQl, tfPluginClient.SubstrateConn, tfPluginClient.NcPool)

tfPluginClient.State = state.NewState(tfPluginClient.NcPool, tfPluginClient.SubstrateConn)

tfPluginClient.Calculator = calculator.NewCalculator(tfPluginClient.SubstrateConn, tfPluginClient.Identity)

return tfPluginClient, nil
Expand Down
23 changes: 23 additions & 0 deletions grid-client/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"reflect"
"slices"
"strings"

"github.com/pkg/errors"
client "github.com/threefoldtech/tfgrid-sdk-go/grid-client/node"
Expand Down Expand Up @@ -297,6 +298,17 @@ func (st *State) LoadNetworkFromGrid(ctx context.Context, name string) (znet wor
return znet, errors.Wrapf(err, "could not get network deployment %d from node %d", contractID, nodeID)
}

if len(strings.TrimSpace(dl.Metadata)) == 0 {
contract, err := sub.GetContract(contractID)
if err != nil {
return znet, errors.Wrapf(err, "could not get contract %d from node %d", contractID, nodeID)
}
dl.Metadata = contract.ContractType.NodeContract.DeploymentData
if len(strings.TrimSpace(dl.Metadata)) == 0 {
return znet, errors.Wrapf(err, "contract %d doesn't have metadata", contractID)
}
}

deploymentData, err := workloads.ParseDeploymentData(dl.Metadata)
if err != nil {
return znet, errors.Wrapf(err, "could not generate deployment metadata for %s", name)
Expand Down Expand Up @@ -403,6 +415,17 @@ func (st *State) GetWorkloadInDeployment(ctx context.Context, nodeID uint32, nam
return gridtypes.Workload{}, gridtypes.Deployment{}, errors.Wrapf(err, "could not get deployment %d from node %d", contractID, nodeID)
}

if len(strings.TrimSpace(dl.Metadata)) == 0 {
contract, err := sub.GetContract(contractID)
if err != nil {
return gridtypes.Workload{}, gridtypes.Deployment{}, errors.Wrapf(err, "could not get contract %d from node %d", contractID, nodeID)
}
dl.Metadata = contract.ContractType.NodeContract.DeploymentData
if len(strings.TrimSpace(dl.Metadata)) == 0 {
return gridtypes.Workload{}, gridtypes.Deployment{}, errors.Wrapf(err, "contract %d doesn't have metadata", contractID)
}
}

dlData, err := workloads.ParseDeploymentData(dl.Metadata)
if err != nil {
return gridtypes.Workload{}, gridtypes.Deployment{}, errors.Wrapf(err, "could not get deployment %d data", contractID)
Expand Down
Loading