Skip to content

Commit

Permalink
merge: branch 'master' into mainnet/main
Browse files Browse the repository at this point in the history
  • Loading branch information
troian committed Apr 19, 2022
2 parents 99c90aa + 9a9a2f9 commit aeffe27
Show file tree
Hide file tree
Showing 20 changed files with 456 additions and 303 deletions.
2 changes: 1 addition & 1 deletion make/codegen.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ kubetypes: $(K8S_GENERATE_GROUPS)
akash.network:v1,v2beta1

.PHONY: proto-gen
proto-gen: $(PROTOC) $(GRPC_GATEWAY) $(PROTOC_GEN_COSMOS) modvendor
proto-gen: $(PROTOC) $(GRPC_GATEWAY) $(PROTOC_GEN_GOCOSMOS) modvendor
./script/protocgen.sh

.PHONY: proto-swagger-gen
Expand Down
68 changes: 34 additions & 34 deletions make/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@ GO := GO111MODULE=$(GO111MODULE) go
# setup .cache bins first in paths to have precedence over already installed same tools for system wide use
PATH := "$(PATH):$(AKASH_DEVCACHE_BIN):$(AKASH_DEVCACHE_NODE_BIN)"

BUF_VERSION ?= 0.35.1
PROTOC_VERSION ?= 3.13.0
PROTOC_GEN_COSMOS_VERSION ?= v0.3.1
GRPC_GATEWAY_VERSION := $(shell $(GO) list -mod=readonly -m -f '{{ .Version }}' github.com/grpc-ecosystem/grpc-gateway)
PROTOC_SWAGGER_GEN_VERSION := $(GRPC_GATEWAY_VERSION)
GOLANGCI_LINT_VERSION ?= v1.38.0
GOLANG_VERSION ?= 1.16.1
STATIK_VERSION ?= v0.1.7
GIT_CHGLOG_VERSION ?= v0.15.1
MODVENDOR_VERSION ?= v0.3.0
MOCKERY_VERSION ?= 2.5.1
K8S_CODE_GEN_VERSION ?= v0.19.3
BUF_VERSION ?= 0.35.1
PROTOC_VERSION ?= 3.13.0
PROTOC_GEN_GOCOSMOS_VERSION ?= v0.3.1
GRPC_GATEWAY_VERSION := $(shell $(GO) list -mod=readonly -m -f '{{ .Version }}' github.com/grpc-ecosystem/grpc-gateway)
PROTOC_SWAGGER_GEN_VERSION := $(GRPC_GATEWAY_VERSION)
GOLANGCI_LINT_VERSION ?= v1.38.0
GOLANG_VERSION ?= 1.16.1
STATIK_VERSION ?= v0.1.7
GIT_CHGLOG_VERSION ?= v0.15.1
MODVENDOR_VERSION ?= v0.3.0
MOCKERY_VERSION ?= 2.5.1
K8S_CODE_GEN_VERSION ?= v0.19.3

# <TOOL>_VERSION_FILE points to the marker file for the installed version.
# If <TOOL>_VERSION_FILE is changed, the binary will be re-downloaded.
PROTOC_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc/$(PROTOC_VERSION)
GRPC_GATEWAY_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc-gen-grpc-gateway/$(GRPC_GATEWAY_VERSION)
PROTOC_GEN_COSMOS_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc-gen-cosmos/$(PROTOC_GEN_COSMOS_VERSION)
STATIK_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/statik/$(STATIK_VERSION)
MODVENDOR_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/modvendor/$(MODVENDOR_VERSION)
GIT_CHGLOG_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/git-chglog/$(GIT_CHGLOG_VERSION)
MOCKERY_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/mockery/v$(MOCKERY_VERSION)
K8S_CODE_GEN_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/k8s-codegen/$(K8S_CODE_GEN_VERSION)

MODVENDOR = $(AKASH_DEVCACHE_BIN)/modvendor
SWAGGER_COMBINE = $(AKASH_DEVCACHE_NODE_BIN)/swagger-combine
PROTOC_SWAGGER_GEN := $(AKASH_DEVCACHE_BIN)/protoc-swagger-gen
PROTOC := $(AKASH_DEVCACHE_BIN)/protoc
STATIK := $(AKASH_DEVCACHE_BIN)/statik
PROTOC_GEN_COSMOS := $(AKASH_DEVCACHE_BIN)/protoc-gen-cosmos
GRPC_GATEWAY := $(AKASH_DEVCACHE_BIN)/protoc-gen-grpc-gateway
GIT_CHGLOG := $(AKASH_DEVCACHE_BIN)/git-chglog
MOCKERY := $(AKASH_DEVCACHE_BIN)/mockery
K8S_GENERATE_GROUPS := $(AKASH_ROOT)/vendor/k8s.io/code-generator/generate-groups.sh
K8S_GO_TO_PROTOBUF := $(AKASH_DEVCACHE_BIN)/go-to-protobuf
KIND := kind
NPM := npm
PROTOC_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc/$(PROTOC_VERSION)
GRPC_GATEWAY_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc-gen-grpc-gateway/$(GRPC_GATEWAY_VERSION)
PROTOC_GEN_GOCOSMOS_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc-gen-gocosmos/$(PROTOC_GEN_GOCOSMOS_VERSION)
STATIK_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/statik/$(STATIK_VERSION)
MODVENDOR_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/modvendor/$(MODVENDOR_VERSION)
GIT_CHGLOG_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/git-chglog/$(GIT_CHGLOG_VERSION)
MOCKERY_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/mockery/v$(MOCKERY_VERSION)
K8S_CODE_GEN_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/k8s-codegen/$(K8S_CODE_GEN_VERSION)

MODVENDOR = $(AKASH_DEVCACHE_BIN)/modvendor
SWAGGER_COMBINE = $(AKASH_DEVCACHE_NODE_BIN)/swagger-combine
PROTOC_SWAGGER_GEN := $(AKASH_DEVCACHE_BIN)/protoc-swagger-gen
PROTOC := $(AKASH_DEVCACHE_BIN)/protoc
STATIK := $(AKASH_DEVCACHE_BIN)/statik
PROTOC_GEN_GOCOSMOS := $(AKASH_DEVCACHE_BIN)/protoc-gen-gocosmos
GRPC_GATEWAY := $(AKASH_DEVCACHE_BIN)/protoc-gen-grpc-gateway
GIT_CHGLOG := $(AKASH_DEVCACHE_BIN)/git-chglog
MOCKERY := $(AKASH_DEVCACHE_BIN)/mockery
K8S_GENERATE_GROUPS := $(AKASH_ROOT)/vendor/k8s.io/code-generator/generate-groups.sh
K8S_GO_TO_PROTOBUF := $(AKASH_DEVCACHE_BIN)/go-to-protobuf
KIND := kind
NPM := npm

include $(AKASH_ROOT)/make/setup-cache.mk
10 changes: 5 additions & 5 deletions make/setup-cache.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ $(PROTOC_VERSION_FILE): $(AKASH_DEVCACHE)
touch $@
$(PROTOC): $(PROTOC_VERSION_FILE)

$(PROTOC_GEN_COSMOS_VERSION_FILE): $(AKASH_DEVCACHE)
@echo "installing protoc-gen-cosmos $(PROTOC_GEN_COSMOS_VERSION) ..."
rm -f $(PROTOC_GEN_COSMOS)
GOBIN=$(AKASH_DEVCACHE_BIN) go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@$(PROTOC_GEN_COSMOS_VERSION)
$(PROTOC_GEN_GOCOSMOS_VERSION_FILE): $(AKASH_DEVCACHE) modvendor
@echo "installing protoc-gen-gocosmos $(PROTOC_GEN_GOCOSMOS_VERSION) ..."
rm -f $(PROTOC_GEN_GOCOSMOS)
GOBIN=$(AKASH_DEVCACHE_BIN) $(GO) install $(ROOT_DIR)/vendor/github.com/regen-network/cosmos-proto/protoc-gen-gocosmos
rm -rf "$(dir $@)"
mkdir -p "$(dir $@)"
touch $@
$(PROTOC_GEN_COSMOS): $(PROTOC_GEN_COSMOS_VERSION_FILE)
$(PROTOC_GEN_GOCOSMOS): $(PROTOC_GEN_GOCOSMOS_VERSION_FILE)

$(GRPC_GATEWAY_VERSION_FILE): $(AKASH_DEVCACHE)
@echo "Installing protoc-gen-grpc-gateway $(GRPC_GATEWAY_VERSION) ..."
Expand Down
5 changes: 0 additions & 5 deletions proto/akash/deployment/v1beta2/deploymentmsg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ message MsgUpdateDeployment {
(gogoproto.jsontag) = "id",
(gogoproto.moretags) = "yaml:\"id\""
];
repeated GroupSpec groups = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "groups",
(gogoproto.moretags) = "yaml:\"groups\""
];
bytes version = 3 [
(gogoproto.jsontag) = "version",
(gogoproto.moretags) = "yaml:\"version\""
Expand Down
4 changes: 3 additions & 1 deletion proto/akash/inflation/v1beta2/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ option go_package = "github.com/ovrclk/akash/x/inflation/types/v1beta2";
// Params defines the parameters for the x/deployment package
message Params {
// InflationDecayFactor is the number of years it takes inflation to halve.
uint32 inflation_decay_factor = 1 [
string inflation_decay_factor = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.customname) = "InflationDecayFactor",
(gogoproto.jsontag) = "inflation_decay_factor",
(gogoproto.moretags) = "yaml:\"inflation_decay_factor\""
Expand Down
45 changes: 45 additions & 0 deletions sdl/_testdata/simple-double-ram.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
version: "2.0"
services:
web:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
profiles:
compute:
web:
resources:
cpu:
units: "100m"
memory:
size: "256Mi"
storage:
size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
web:
denom: uakt
amount: 50
deployment:
web:
westcoast:
profile: web
count: 2
68 changes: 49 additions & 19 deletions sdl/sdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,56 @@ import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

func TestSdlVersion(t *testing.T) {
stream := `
version: v2.0
services:
web:
image: quay.io/ovrclk/demo-app
expose:
- port: 80
as: 80
accept:
- hello.localhost
to:
- global: true
`

var sdl sdl

err := yaml.Unmarshal([]byte(stream), &sdl)
func TestSDLManifestVersion(t *testing.T) {
obj, err := ReadFile("_testdata/simple.yaml")
require.NoError(t, err)

m, err := obj.Manifest()
require.NoError(t, err)

version, err := ManifestVersion(m)
require.NoError(t, err)
// Should return a value
require.NotEmpty(t, version)

obj, err = ReadFile("_testdata/private_service.yaml")
require.NoError(t, err)

m, err = obj.Manifest()
require.NoError(t, err)

secondVersion, err := ManifestVersion(m)
require.NoError(t, err)
// Should return a value
require.NotEmpty(t, secondVersion)
// Should be different than the first
require.NotEqual(t, secondVersion, version)
}

func TestSDLManifestVersionChangesWithVersion(t *testing.T) {
obj, err := ReadFile("_testdata/simple.yaml")
require.NoError(t, err)

m, err := obj.Manifest()
require.NoError(t, err)

version, err := ManifestVersion(m)
require.NoError(t, err)
// Should return a value
require.NotEmpty(t, version)

obj, err = ReadFile("_testdata/simple-double-ram.yaml")
require.NoError(t, err)

m, err = obj.Manifest()
require.NoError(t, err)

secondVersion, err := ManifestVersion(m)
require.NoError(t, err)
// Should return a value
require.NotEmpty(t, secondVersion)
// Should be different than the first
require.NotEqual(t, secondVersion, version)
}
3 changes: 2 additions & 1 deletion tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

package tools

//nolint
// nolint
import (
_ "github.com/regen-network/cosmos-proto/protoc-gen-gocosmos"
_ "k8s.io/code-generator"
_ "sigs.k8s.io/kind"
)
35 changes: 29 additions & 6 deletions x/deployment/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"os"
"reflect"
"strings"
"time"

Expand All @@ -22,6 +23,11 @@ import (
"github.com/spf13/cobra"
)

var (
errDeploymentUpdate = errors.New("deployment update failed")
errDeploymentUpdateGroupsChanged = fmt.Errorf("%w: groups are different than existing deployment, you cannot update groups", errDeploymentUpdate)
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd(key string) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -219,26 +225,43 @@ func cmdUpdate(key string) *cobra.Command {
if err != nil {
return err
}

version, err := sdl.Version(sdlManifest)
if err != nil {
return err
}

groups, err := sdlManifest.DeploymentGroups()
if err != nil {
return err
}

version, err := sdl.Version(sdlManifest)
// Query the RPC node to make sure the existing groups are identical
queryClient := types.NewQueryClient(clientCtx)
existingDeployment, err := queryClient.Deployment(cmd.Context(), &types.QueryDeploymentRequest{
ID: id,
})
if err != nil {
return err
}

// do not send the transaction if the groups have changed
existingGroups := existingDeployment.GetGroups()
if len(existingGroups) != len(groups) {
return errDeploymentUpdateGroupsChanged
}

for i, existingGroup := range existingGroups {
if reflect.DeepEqual(groups[i], existingGroup.GroupSpec) {
return errDeploymentUpdateGroupsChanged
}
}

warnIfGroupVolumesExceeds(clientCtx, groups)

msg := &types.MsgUpdateDeployment{
ID: id,
Version: version,
Groups: make([]types.GroupSpec, 0, len(groups)),
}

for _, group := range groups {
msg.Groups = append(msg.Groups, *group)
}

return sdkutil.BroadcastTX(cmd.Context(), clientCtx, cmd.Flags(), msg)
Expand Down
Loading

0 comments on commit aeffe27

Please sign in to comment.