Skip to content

Commit

Permalink
fix(provider): apply missing volume templates on deployment update
Browse files Browse the repository at this point in the history
if deployment with persistent storage is being updated it should
reuse existing persistent volume templates

ref #286

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jul 1, 2022
1 parent 20a3b6b commit 999ec6d
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(E2EApp))
suite.Run(t, new(E2EPersistentStorageDefault))
suite.Run(t, new(E2EPersistentStorageBeta2))
suite.Run(t, new(E2EPersistentStorageDeploymentUpdate))
suite.Run(t, new(E2EMigrateHostname))
suite.Run(t, new(E2EJWTServer))
suite.Run(t, &E2EIPAddress{IntegrationTestSuite{ipMarketplace: true}})
Expand Down
101 changes: 101 additions & 0 deletions integration/persistentstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type E2EPersistentStorageBeta2 struct {
IntegrationTestSuite
}

type E2EPersistentStorageDeploymentUpdate struct {
IntegrationTestSuite
}

func (s *E2EPersistentStorageDefault) TestDefaultStorageClass() {
deploymentPath, err := filepath.Abs("../x/deployment/testdata/deployment-v2-storage-default.yaml")
s.Require().NoError(err)
Expand Down Expand Up @@ -230,3 +234,100 @@ func (s *E2EPersistentStorageBeta2) TestDedicatedStorageClass() {
s.Require().NoError(err)
s.Require().Equal(testData.String(), string(bodyData))
}

func (s *E2EPersistentStorageDeploymentUpdate) TestDeploymentUpdate() {
// create a deployment
deploymentPath, err := filepath.Abs("../x/deployment/testdata/deployment-v2-storage-updateA.yaml")
s.Require().NoError(err)

deploymentID := dtypes.DeploymentID{
Owner: s.keyTenant.GetAddress().String(),
DSeq: uint64(102),
}

// Create Deployments
res, err := deploycli.TxCreateDeploymentExec(
s.validator.ClientCtx,
s.keyTenant.GetAddress(),
deploymentPath,
cliGlobalFlags(fmt.Sprintf("--dseq=%v", deploymentID.DSeq))...,
)
s.Require().NoError(err)
s.Require().NoError(s.waitForBlocksCommitted(3))
clitestutil.ValidateTxSuccessful(s.T(), s.validator.ClientCtx, res.Bytes())

bidID := mtypes.MakeBidID(
mtypes.MakeOrderID(dtypes.MakeGroupID(deploymentID, 1), 1),
s.keyProvider.GetAddress(),
)
// check bid
_, err = mcli.QueryBidExec(s.validator.ClientCtx, bidID)
s.Require().NoError(err)

// create lease
_, err = mcli.TxCreateLeaseExec(
s.validator.ClientCtx,
bidID,
s.keyTenant.GetAddress(),
cliGlobalFlags()...,
)
s.Require().NoError(err)
s.Require().NoError(s.waitForBlocksCommitted(2))
clitestutil.ValidateTxSuccessful(s.T(), s.validator.ClientCtx, res.Bytes())

// Assert provider made bid and created lease; test query leases ---------
resp, err := mcli.QueryLeasesExec(s.validator.ClientCtx.WithOutputFormat("json"))
s.Require().NoError(err)

leaseRes := &mtypes.QueryLeasesResponse{}
err = s.validator.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), leaseRes)
s.Require().NoError(err)

s.Require().Len(leaseRes.Leases, 1)

lease := newestLease(leaseRes.Leases)
lid := lease.LeaseID
did := lease.GetLeaseID().DeploymentID()
s.Require().Equal(s.keyProvider.GetAddress().String(), lid.Provider)

// Send Manifest to Provider
_, err = ptestutil.TestSendManifest(
s.validator.ClientCtx.WithOutputFormat("json"),
lid.BidID(),
deploymentPath,
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.keyTenant.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagHome, s.validator.ClientCtx.HomeDir),
)

s.Require().NoError(err)
s.Require().NoError(s.waitForBlocksCommitted(2))

appURL := fmt.Sprintf("http://%s:%s/", s.appHost, s.appPort)
queryAppWithHostname(s.T(), appURL, 50, "testupdatea.localhost")

deploymentPath, err = filepath.Abs("../x/deployment/testdata/deployment-v2-storage-updateB.yaml")
s.Require().NoError(err)

res, err = deploycli.TxUpdateDeploymentExec(s.validator.ClientCtx,
s.keyTenant.GetAddress(),
deploymentPath,
cliGlobalFlags(fmt.Sprintf("--owner=%s", lease.GetLeaseID().Owner),
fmt.Sprintf("--dseq=%v", did.GetDSeq()))...,
)
s.Require().NoError(err)
s.Require().NoError(s.waitForBlocksCommitted(2))
clitestutil.ValidateTxSuccessful(s.T(), s.validator.ClientCtx, res.Bytes())

// Send Updated Manifest to Provider
_, err = ptestutil.TestSendManifest(
s.validator.ClientCtx.WithOutputFormat("json"),
lid.BidID(),
deploymentPath,
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.keyTenant.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagHome, s.validator.ClientCtx.HomeDir),
)
s.Require().NoError(err)
s.Require().NoError(s.waitForBlocksCommitted(2))
queryAppWithHostname(s.T(), appURL, 50, "testupdatea.localhost")
queryAppWithHostname(s.T(), appURL, 50, "testupdateb.localhost")
}
2 changes: 1 addition & 1 deletion provider/cluster/kube/builder/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b *statefulSet) Update(obj *appsv1.StatefulSet) (*appsv1.StatefulSet, erro
obj.Spec.Template.Labels = b.labels()
obj.Spec.Template.Spec.Containers = []corev1.Container{b.container()}
obj.Spec.Template.Spec.ImagePullSecrets = b.imagePullSecrets()
obj.Spec.VolumeClaimTemplates = []corev1.PersistentVolumeClaim{}
obj.Spec.VolumeClaimTemplates = b.persistentVolumeClaims()

return obj, nil
}
42 changes: 42 additions & 0 deletions x/deployment/testdata/deployment-v2-storage-updateA.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
version: "2.0"

services:
web:
image: quay.io/ovrclk/demo-app
expose:
- port: 80
to:
- global: true
accept:
- testupdatea.localhost
params:
storage:
data:
mount: /var/lib/e2e-test
profiles:
compute:
web:
resources:
cpu:
units: "0.01"
memory:
size: "128Mi"
storage:
- size: "512Mi"
- name: data
size: "128Mi"
attributes:
persistent: "true"
placement:
global:
pricing:
web:
denom: uakt
amount: 10

deployment:
web:
global:
profile: web
count: 1
43 changes: 43 additions & 0 deletions x/deployment/testdata/deployment-v2-storage-updateB.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
version: "2.0"

services:
web:
image: quay.io/ovrclk/demo-app
expose:
- port: 80
to:
- global: true
accept:
- testupdatea.localhost
- testupdateb.localhost
params:
storage:
data:
mount: /var/lib/e2e-test
profiles:
compute:
web:
resources:
cpu:
units: "0.01"
memory:
size: "128Mi"
storage:
- size: "512Mi"
- name: data
size: "128Mi"
attributes:
persistent: "true"
placement:
global:
pricing:
web:
denom: uakt
amount: 10

deployment:
web:
global:
profile: web
count: 1

0 comments on commit 999ec6d

Please sign in to comment.