-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply pvc & upgrade image test added in long running
- Loading branch information
1 parent
6297ac8
commit 73d0d9b
Showing
8 changed files
with
151 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package longrunning | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
) | ||
|
||
func TestImageUpgrade(t *testing.T) { | ||
const ( | ||
instanceName = "image-upgrade" | ||
firstImage = "alpine:3.20.3" | ||
secondImage = "nginx:latest" | ||
volumeSize = "1Gi" | ||
volumePath = "/tmp/test-id" | ||
fileContent = "hello world" | ||
filePath = volumePath + "/test-id.txt" | ||
) | ||
|
||
ctx := context.Background() | ||
|
||
ins1, err := createInstance(ctx, instanceName, "", firstImage) | ||
require.NoError(t, err) | ||
|
||
err = ins1.Storage().AddVolume(volumePath, resource.MustParse(volumeSize)) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, ins1.Execution().Start(ctx)) | ||
|
||
testScope := ins1.Scope | ||
t.Logf("Scope: %s", testScope) | ||
|
||
_, err = ins1.Execution().ExecuteCommand(ctx, "echo", fileContent, ">", filePath) | ||
require.NoError(t, err) | ||
|
||
t.Logf("Waiting for 5 seconds to simulate a long running process") | ||
time.Sleep(5 * time.Second) | ||
|
||
ins2, err := createInstance(ctx, instanceName, testScope, firstImage) | ||
require.NoError(t, err) | ||
|
||
err = ins2.Storage().AddVolume(volumePath, resource.MustParse(volumeSize)) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, ins2.Execution().Start(ctx)) | ||
|
||
// To upgrade the image, first the instance must be stopped | ||
require.NoError(t, ins2.Execution().Stop(ctx)) | ||
|
||
// Now we can upgrade the image | ||
require.NoError(t, ins2.Build().SetImage(ctx, secondImage)) | ||
require.NoError(t, ins2.Build().Commit(ctx)) | ||
require.NoError(t, ins2.Execution().Start(ctx)) | ||
|
||
// Test if the alpine image is replaced with the nginx image successfully | ||
out, err := ins2.Execution().ExecuteCommand(ctx, "cat", "/etc/nginx/nginx.conf") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, out) | ||
|
||
// Test if the volume is persisted across the image upgrade | ||
out, err = ins2.Execution().ExecuteCommand(ctx, "cat", filePath) | ||
require.NoError(t, err) | ||
require.Contains(t, out, fileContent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package longrunning | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/celestiaorg/knuu/pkg/instance" | ||
"github.com/celestiaorg/knuu/pkg/knuu" | ||
) | ||
|
||
const ( | ||
testTimeout = time.Minute * 5 | ||
) | ||
|
||
func createInstance(ctx context.Context, name, testScope string, image string) (*instance.Instance, error) { | ||
knOpts := knuu.Options{Timeout: testTimeout, SkipCleanup: true} | ||
if testScope != "" { | ||
knOpts.Scope = testScope | ||
} | ||
|
||
kn, err := knuu.New(ctx, knOpts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
kn.HandleStopSignal(ctx) | ||
|
||
ins, err := kn.NewInstance(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Build().SetImage(ctx, image); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Build().Commit(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Build().SetStartCommand("sleep", "infinity"); err != nil { | ||
return nil, err | ||
} | ||
|
||
return ins, nil | ||
} | ||
|
||
func createInstanceAndStart(ctx context.Context, name, testScope string, image string) (*instance.Instance, error) { | ||
ins, err := createInstance(ctx, name, testScope, image) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := ins.Execution().Start(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
return ins, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters