Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: registry addon #170

Merged
merged 8 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@ go 1.17

require (
cloud.google.com/go/container v1.0.0
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/blang/semver/v4 v4.0.0
github.com/containerd/containerd v1.5.8 // indirect
github.com/docker/docker v20.10.11+incompatible
github.com/docker/go-connections v0.4.0 // indirect
github.com/google/go-github/v39 v39.2.0
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0 // indirect
github.com/kong/go-kong v0.24.0
github.com/mitchellh/go-homedir v1.1.0
github.com/morikuni/aec v1.0.0 // indirect
github.com/sethvargo/go-password v0.2.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20211008194852-3b03d305991f // indirect
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/api v0.60.0
google.golang.org/genproto v0.0.0-20211021150943-2b146023228c
google.golang.org/grpc v1.41.0 // indirect
k8s.io/api v0.22.4
k8s.io/apiextensions-apiserver v0.22.4
k8s.io/apimachinery v0.22.4
k8s.io/client-go v0.22.4
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/jetstack/cert-manager v1.6.1
github.com/opencontainers/image-spec v1.0.2 // indirect
)

require github.com/docker/go-connections v0.4.0 // indirect

require (
cloud.google.com/go v0.97.0 // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403 // indirect
Expand All @@ -52,7 +54,7 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -63,8 +65,8 @@ require (
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -74,11 +76,14 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
437 changes: 433 additions & 4 deletions go.sum

Large diffs are not rendered by default.

55 changes: 53 additions & 2 deletions internal/cmd/ktf/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"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/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/registry"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/types/kind"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ var environmentsCreateCmd = &cobra.Command{
}

// configure any addons that need to be deployed with the environment's cluster
configureAddons(cmd, builder, deployAddons)
callbacks := configureAddons(cmd, builder, deployAddons)

fmt.Printf("building new environment %s\n", builder.Name)
env, err := builder.Build(ctx)
Expand All @@ -101,11 +102,19 @@ var environmentsCreateCmd = &cobra.Command{
cobra.CheckErr(<-env.WaitForReady(ctx))

fmt.Printf("environment %s was created successfully!\n", env.Name())
for _, callback := range callbacks {
callback()
}
},
}

func configureAddons(cmd *cobra.Command, builder *environments.Builder, addons []string) {
func configureAddons(cmd *cobra.Command, builder *environments.Builder, addons []string) []func() {
invalid, dedup := make([]string, 0), make(map[string]bool)
// sometimes some addons which are configured for need to do something AFTER
// the addon itself has successfully deployed, usually something like helpful
// logging messages.
callbacks := make([]func(), 0)

for _, addon := range addons {
// load any valid addons, and check for invalid addons
switch addon {
Expand All @@ -125,6 +134,46 @@ func configureAddons(cmd *cobra.Command, builder *environments.Builder, addons [
builder = builder.WithAddons(httpbin.New())
case "cert-manager":
builder = builder.WithAddons(certmanager.New())
case "registry":
registryAddon := registry.NewBuilder().
WithServiceTypeLoadBalancer().
Build()
builder = builder.WithAddons(registryAddon)
registryInfoCallback := func() {
fmt.Printf(`
Registry Addon HELP:

You have installed the registry addon deployed with an SSL certificate provided
by cert-manager. The default certificate used is a self-signed certificate.
As such if you try to push images to this registry with the standard:

$ docker push ${REGISTRY_IP}/image

Without first adding its certificate to your local docker (or other client) chain
of trust it will fail. The following provides an example of how to add the certificate
using a standard docker installation on a Linux system where "/etc/docker" is the
configuration directory for docker:

$ REGISTRY_IP="$(kubectl -n %s get svc registry -o=go-template='{{(index .status.loadBalancer.ingress 0).ip}}')"
$ sudo mkdir -p /etc/docker/certs.d/${REGISTRY_IP}/
$ kubectl -n %s get secrets registry-cert-secret -o=go-template='{{index .data "ca.crt"}}' | base64 -d | sudo tee /etc/docker/certs.d/${REGISTRY_IP}/ca.crt

Note that this generally is not going to work verbatim on all systems and the
above instructions should be considered just an example. Adjust for your own
system and docker installation. You may also need to change ".ip" for ".host"
if your service is provided a DNS name instead of an IP for its LB address.

Afterwards you should be able to push images to the registry, e.g.:

$ docker pull kennethreitz/httpbin
$ docker tag kennethreitz/httpbin ${REGISTRY_IP}/httpbin
$ docker push ${REGISTRY_IP}/httpbin

Images pushed this way should be immediately usable in pod configurations
on the cluster as the certificate is automatically configured on the nodes.
`, registryAddon.Namespace(), registryAddon.Namespace())
}
callbacks = append(callbacks, registryInfoCallback)
default:
invalid = append(invalid, addon)
}
Expand All @@ -139,6 +188,8 @@ func configureAddons(cmd *cobra.Command, builder *environments.Builder, addons [
if len(invalid) > 0 {
cobra.CheckErr(fmt.Errorf("%d addons were invalid: %s", len(invalid), invalid))
}

return callbacks
}

func configureKongAddon(cmd *cobra.Command, envBuilder *environments.Builder) *environments.Builder {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/ktf/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (

// EnvironmentCreateTimeout indicates the amount of time maximum that should
// be allowed to wait for a test environment to finish creating.
EnvironmentCreateTimeout = time.Minute * 5
EnvironmentCreateTimeout = time.Minute * 10

// EnvironmentDeleteTimeout indicates the amount of time maximum that should
// be allowed to wait for a test environment to delete successfully.
Expand Down
15 changes: 11 additions & 4 deletions pkg/clusters/addons/certmanager/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const (

// DefaultNamespace indicates the default namespace this addon will be deployed to.
DefaultNamespace = "cert-manager"

// DefaultIssuerName is the name of the default issuer that is provided
// with the certmanager addon installation.
DefaultIssuerName = "selfsigned"
)

type Addon struct {
Expand Down Expand Up @@ -188,21 +192,24 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime.
const (
manifestFormatter = "https://github.com/jetstack/cert-manager/releases/download/v%s/cert-manager.yaml"
defaultIssuerWaitSeconds = 60
defaultIssuer = `---
)

var (
defaultIssuer = fmt.Sprintf(`---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: selfsigned
name: %s
spec:
selfSigned: {}
`
`, DefaultIssuerName)
)

func (a *Addon) deployDefaultIssuer(ctx context.Context, cluster clusters.Cluster) error {
if err := clusters.ApplyYAML(ctx, cluster, defaultIssuer); err != nil {
return err
}
return clusters.WaitForCondition(ctx, cluster, DefaultNamespace, "clusterissuers.cert-manager.io", "selfsigned", "Ready", defaultIssuerWaitSeconds)
return clusters.WaitForCondition(ctx, cluster, DefaultNamespace, "clusterissuers.cert-manager.io", DefaultIssuerName, "Ready", defaultIssuerWaitSeconds)
}

func (a *Addon) cleanupDefaultIssuer(ctx context.Context, cluster clusters.Cluster) error {
Expand Down
Loading