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

Add MC transit gateway reconciler #69

Merged
merged 18 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added ManagementClusterTransitGateway reconciler. This reconciler is still disabled and is part of the merger of the aws-network-topology-operator.

### Changed

- Update `golang.org/x/net` package.
Expand Down
22 changes: 18 additions & 4 deletions Makefile.custom.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ test-unit: ginkgo generate fmt vet envtest ## Run unit tests
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GINKGO) -p --nodes 4 -r -randomize-all --randomize-suites --skip-package=tests --cover --coverpkg=`go list ./... | grep -v fakes | tr '\n' ','` ./...

.PHONY: test-integration
test-integration: ginkgo generate fmt vet ## Run integration tests
docker-compose up -d
test-integration: ginkgo start-localstack ## Run integration tests
sleep 4
AWS_ACCESS_KEY_ID="dummy" AWS_SECRET_ACCESS_KEY="dummy" AWS_ENDPOINT="http://localhost:4566" $(GINKGO) -p --nodes 4 -r -randomize-all --randomize-suites --cover --coverpkg=github.com/aws-resolver-rules-operator/pkg/aws tests/integration
docker-compose down
AWS_ACCESS_KEY_ID="dummy" AWS_SECRET_ACCESS_KEY="dummy" AWS_ENDPOINT="http://localhost:4566" AWS_REGION="eu-central-1" $(GINKGO) -p --nodes 4 -r -randomize-all --randomize-suites --cover --coverpkg=github.com/aws-resolver-rules-operator/pkg/aws tests/integration
$(MAKE) stop-localstack

.PHONY: start-localstack
start-localstack: docker-compose ## Run localstack with docker-compose
$(DOCKER_COMPOSE) up --detach --wait

.PHONY: stop-localstack
stop-localstack: docker-compose ## Run localstack with docker-compose
$(DOCKER_COMPOSE) stop

.PHONY: test-all
test-all: test-unit test-integration ## Run all tests
Expand All @@ -44,6 +51,13 @@ GINKGO = $(shell pwd)/bin/ginkgo
ginkgo: ## Download ginkgo locally if necessary.
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@latest)

DOCKER_COMPOSE = $(shell pwd)/bin/docker-compose
.PHONY: docker-compose
docker-compose: ## Download docker-compose locally if necessary.
$(eval LATEST_RELEASE = $(shell curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r '.tag_name'))
curl -sL "https://github.com/docker/compose/releases/download/$(LATEST_RELEASE)/docker-compose-linux-x86_64" -o $(DOCKER_COMPOSE)
chmod +x $(DOCKER_COMPOSE)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
Expand Down
111 changes: 110 additions & 1 deletion controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ limitations under the License.
package controllers_test

import (
"context"
"go/build"
"path/filepath"
"testing"

"github.com/giantswarm/aws-network-topology-operator/tests"
"github.com/go-logr/logr"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubectl/pkg/scheme"
capa "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
capi "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
Expand All @@ -37,7 +49,10 @@ func TestControllers(t *testing.T) {
}

var (
logger logr.Logger
logger logr.Logger
k8sClient client.Client
testEnv *envtest.Environment
namespace string
)

var _ = BeforeSuite(func() {
Expand All @@ -48,4 +63,98 @@ var _ = BeforeSuite(func() {
}
logger = zap.New(zap.UseFlagOptions(&opts))
logf.SetLogger(logger)
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

tests.GetEnvOrSkip("KUBEBUILDER_ASSETS")

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api@v1.2.1", "config", "crd", "bases"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api-provider-aws@v1.5.0", "config", "crd", "bases"),
},
ErrorIfCRDPathMissing: true,
mnitchev marked this conversation as resolved.
Show resolved Hide resolved
}

cfg, err := testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

err = capa.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

err = capi.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
if testEnv == nil {
return
}
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})

var _ = BeforeEach(func() {
namespace = uuid.New().String()
namespaceObj := &corev1.Namespace{}
namespaceObj.Name = namespace
Expect(k8sClient.Create(context.Background(), namespaceObj)).To(Succeed())
})

var _ = AfterEach(func() {
namespaceObj := &corev1.Namespace{}
namespaceObj.Name = namespace
Expect(k8sClient.Delete(context.Background(), namespaceObj)).To(Succeed())
})

func newCluster(name string, annotationsKeyValues ...string) *capa.AWSCluster {
if len(annotationsKeyValues)%2 != 0 {
Fail("wrong number of arguments for newCluster. Expected even number of arguments for annotation key/value pairs")
}

annotations := map[string]string{}
for i := 0; i < len(annotationsKeyValues); i += 2 {
annotations[annotationsKeyValues[i]] = annotationsKeyValues[i+1]
}

vpcID := uuid.NewString()
awsCluster := &capa.AWSCluster{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: annotations,
},
Spec: capa.AWSClusterSpec{
NetworkSpec: capa.NetworkSpec{
VPC: capa.VPCSpec{
ID: vpcID,
},
Subnets: capa.Subnets{
{
ID: "sub-1",
IsPublic: false,
},
},
},
},
}

Expect(k8sClient.Create(context.Background(), awsCluster)).To(Succeed())
tests.PatchAWSClusterStatus(k8sClient, awsCluster, capa.AWSClusterStatus{
Ready: true,
})

return awsCluster
}

func newRandomCluster(annotationsKeyValues ...string) *capa.AWSCluster {
name := uuid.NewString()
return newCluster(name, annotationsKeyValues...)
}
160 changes: 160 additions & 0 deletions controllers/controllersfakes/fake_awscluster_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading