Add tests for preupgradchecks and spec/archive CLI (#2874)

* Add tests for preupgradchecks
* Add spec tests
* Add package archive tests
* Wait for cleanup
* Fix test and coverage

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2023-11-17 14:08:38 +05:30
committed by GitHub
parent e7d6381876
commit d23ed572f9
18 changed files with 186 additions and 77 deletions
+6 -6
View File
@@ -124,7 +124,7 @@ func (client *PreUpgradeTaskClient) LatestSchemaApplied(ctx context.Context) err
// VerifyFunctionSpecReferences verifies that a function references secrets, configmaps, pkgs in its own namespace and
// outputs a list of functions that don't adhere to this requirement.
func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Context) {
func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Context) error {
client.logger.Info("verifying function spec references for all functions in the cluster")
var err error
@@ -140,9 +140,11 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Con
}
if err != nil {
client.logger.Fatal("error listing functions after max retries",
client.logger.Error("error listing functions after max retries",
zap.Error(err),
zap.Int("max_retries", maxRetries))
errs = errors.Join(errs, fmt.Errorf("error listing functions in namespace : %s", namespace))
continue
}
// check that all secrets, configmaps, packages are in the same namespace
@@ -169,10 +171,8 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Con
}
if errs != nil {
client.logger.Fatal("installation failed",
zap.Error(errs),
zap.String("summary", "a function cannot reference secrets, configmaps and packages outside it's own namespace"))
return errs
}
client.logger.Info("function spec references verified")
return nil
}
+31
View File
@@ -0,0 +1,31 @@
package main
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/fission/fission/test/e2e/framework"
)
func TestPreUpgradeTaskClient(t *testing.T) {
f := framework.NewFramework()
defer f.Logger().Sync()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := f.Start(ctx)
require.NoError(t, err)
preupgradeClient, err := makePreUpgradeTaskClient(f.ClientGen(), f.Logger())
require.NoError(t, err)
crd := preupgradeClient.GetFunctionCRD(ctx)
require.NotNil(t, crd)
err = preupgradeClient.LatestSchemaApplied(ctx)
require.NoError(t, err)
err = preupgradeClient.VerifyFunctionSpecReferences(ctx)
require.NoError(t, err)
}
+9 -6
View File
@@ -28,22 +28,25 @@ func main() {
logger := loggerfactory.GetLogger()
defer logger.Sync()
crdBackedClient, err := makePreUpgradeTaskClient(crd.NewClientGenerator(), logger)
ctx := signals.SetupSignalHandler()
preupgradeClient, err := makePreUpgradeTaskClient(crd.NewClientGenerator(), logger)
if err != nil {
logger.Fatal("error creating a crd client, please retry helm upgrade",
zap.Error(err))
}
ctx := signals.SetupSignalHandler()
crd := crdBackedClient.GetFunctionCRD(ctx)
crd := preupgradeClient.GetFunctionCRD(ctx)
if crd == nil {
logger.Info("nothing to do since CRDs are not present on the cluster")
return
}
err = crdBackedClient.LatestSchemaApplied(ctx)
err = preupgradeClient.LatestSchemaApplied(ctx)
if err != nil {
logger.Fatal("New CRDs are not applied", zap.Error(err))
}
crdBackedClient.VerifyFunctionSpecReferences(ctx)
err = preupgradeClient.VerifyFunctionSpecReferences(ctx)
if err != nil {
logger.Fatal("Function spec references are not valid", zap.Error(err))
}
}