Skip to content

Commit

Permalink
Fix Kuma issues and release 0.15.1 (#311)
Browse files Browse the repository at this point in the history
* fix: add Kuma CLI

* fix: add retry to Kuma mesh installation

Add a retry mechanism to the Kuma mesh installation, to avoid webhook
failures while the deployment is coming online.

* chore: add Kuma test

* chore: remove unused fields and functions

* chore: add 0.15.1 changelog

Co-authored-by: Jarek Mróz <[email protected]>
  • Loading branch information
rainest and jrsmroz committed Jul 4, 2022
1 parent 1ca42e8 commit da91d21
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## v0.15.1

- Added missing Kuma addon CLI entry.
- Retry Kuma mesh installations to handle delayed webhook start.

### Improvements

- Update metallb to `v0.12.1`.
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/ktf/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/httpbin"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/istio"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kuma"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/registry"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/types/kind"
Expand Down Expand Up @@ -137,6 +138,8 @@ func configureAddons(cmd *cobra.Command, builder *environments.Builder, addons [
builder = builder.WithAddons(httpbin.New())
case "cert-manager":
builder = builder.WithAddons(certmanager.New())
case "kuma":
builder = builder.WithAddons(kuma.New())
case "registry":
registryAddon := registry.NewBuilder().
WithServiceTypeLoadBalancer().
Expand Down
32 changes: 13 additions & 19 deletions pkg/clusters/addons/kuma/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import (

"github.com/blang/semver/v4"
"github.com/sirupsen/logrus"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/kong/kubernetes-testing-framework/internal/utils"
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
"github.com/kong/kubernetes-testing-framework/pkg/utils/github"
)

// -----------------------------------------------------------------------------
Expand All @@ -47,9 +44,7 @@ type Addon struct {
name string
logger *logrus.Logger

version semver.Version
kumaDeployScript *corev1.ConfigMap
kumaDeployJob *batchv1.Job
version semver.Version

mtlsEnabled bool
}
Expand Down Expand Up @@ -200,17 +195,6 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) (waitForObj
// Kuma Addon - Private Methods
// -----------------------------------------------------------------------------

// useLatestKumaVersion locates and sets the kuma version to deploy to the latest
// non-prelease tag found.
func (a *Addon) useLatestKumaVersion() error {
latestVersion, err := github.FindLatestReleaseForRepo("kumahq", "kuma")
if err != nil {
return err
}
a.version = *latestVersion
return nil
}

// TODO this actually just clobbers the default mesh, which ideally we don't want to do
// however, Kuma apparently doesn't have a clientset, so vov. could do JSON patches, but eh

Expand All @@ -234,6 +218,16 @@ spec:
enabledBackend: ca-1`
)

func (a *Addon) enableMTLS(ctx context.Context, cluster clusters.Cluster) error {
return clusters.ApplyYAML(ctx, cluster, mtlsEnabledDefaultMesh)
// enableMTLS attempts to apply a Mesh resource with a basic retry mechanism to deal with delays in the Kuma webhook
// startup
func (a *Addon) enableMTLS(ctx context.Context, cluster clusters.Cluster) (err error) {
for i := 0; i < 5; i++ {
err = clusters.ApplyYAML(ctx, cluster, mtlsEnabledDefaultMesh)
if err != nil {
time.Sleep(time.Second * 5) //nolint:gomnd
} else {
break
}
}
return err
}
82 changes: 82 additions & 0 deletions test/integration/kuma_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//go:build integration_tests
// +build integration_tests

package integration

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kuma"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
)

func TestEnvironmentWithKuma(t *testing.T) {
t.Parallel()

t.Log("configuring the testing environment")
addon := kuma.New()
builder := environments.NewBuilder().WithAddons(addon)

t.Log("building the testing environment and Kubernetes cluster")
env, err := builder.Build(ctx)
require.NoError(t, err)

t.Logf("setting up the environment cleanup for environment %s and cluster %s", env.Name(), env.Cluster().Name())
defer func() {
t.Logf("cleaning up environment %s and cluster %s", env.Name(), env.Cluster().Name())
require.NoError(t, env.Cleanup(ctx))
}()

t.Log("verifying that addons have been loaded into the environment")
require.Len(t, env.Cluster().ListAddons(), 1)

t.Log("waiting for the test environment to be ready for use")
require.NoError(t, <-env.WaitForReady(ctx))

t.Log("verifying the test environment becomes ready for use")
waitForObjects, ready, err := env.Ready(ctx)
require.NoError(t, err)
require.Len(t, waitForObjects, 0)
require.True(t, ready)

t.Log("verifying that the kuma addon has become ready for use")
waitForObjects, ready, err = addon.Ready(ctx, env.Cluster())
require.NoError(t, err)
require.Len(t, waitForObjects, 0)
require.True(t, ready)

t.Log("verifying that kuma deployments are up and running")
require.Eventually(t, func() bool {
foundDeployments := map[string]bool{
"kuma-control-plane": false,
}
deploymentList, err := env.Cluster().Client().AppsV1().Deployments(kuma.Namespace).List(ctx, metav1.ListOptions{})
if err == nil {
for _, deployment := range deploymentList.Items {
if *deployment.Spec.Replicas == deployment.Status.ReadyReplicas {
foundDeployments[deployment.Name] = true
}
}
}
for _, found := range foundDeployments {
if !found {
return false
}
}
return true
}, time.Minute, time.Second*5)

t.Log("cleaning up the kuma addon")
require.NoError(t, env.Cluster().DeleteAddon(ctx, addon))
assert.Len(t, env.Cluster().ListAddons(), 0)

t.Log("ensuring that the kuma addon is cleaned up successfully")
deploys, err := env.Cluster().Client().AppsV1().Deployments(kuma.Namespace).List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Len(t, deploys.Items, 0)
}

0 comments on commit da91d21

Please sign in to comment.