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

TEST Golangci lint GitHub action integ #2

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5de8f32
add CRD doc generator (#505)
mikhail-aws Nov 15, 2023
5f97041
Upgrade [email protected] / [email protected] (#503)
Nov 16, 2023
89b5b86
Minor update to documentation for deploy, overview, and readme.md pag…
graehren Nov 16, 2023
a25205c
Remove deprecated gateway annotation in docs. Improve getstarted.md (…
zijun726911 Nov 16, 2023
6a6c8b5
Fix target group leaking and e2etest (#510)
Nov 16, 2023
1fd61c1
Update crds (#511)
Nov 16, 2023
de47ec1
Added automatic api reference generation (#507)
xWink Nov 16, 2023
a50ab17
Pass defaultServiceNetwork env variable (#512)
zijun726911 Nov 16, 2023
8998615
Doc: Rework documentation site structure (#513)
graehren Nov 17, 2023
68dbdcf
HTTPRoute, Service, and IAMAuthPolicy Documentation Enhancements (#514)
xWink Nov 17, 2023
f9d8f34
Update deployment instructions (#516)
Nov 17, 2023
24a25cf
doc: fix doc build (#517)
graehren Nov 17, 2023
42cbb61
Fix e2e tests and examples to be compatible w/ latest CRDs (#515)
Nov 17, 2023
61689bc
Update Gateway docs and fix styles (#518)
Nov 17, 2023
ed90166
add target group policy controller and status updates (#509)
mikhail-aws Nov 17, 2023
649eb2d
Doc: Update Readme Links (#521)
graehren Nov 17, 2023
72cd58c
Docs: move envvar section and fix links (#522)
Nov 17, 2023
291ca95
Doc: Update Target Group Policy documentation (#523)
graehren Nov 17, 2023
7c2c8ab
fix crd autogen (#524)
mikhail-aws Nov 17, 2023
af28cb1
update on AccessLogPolicy and TargetGroupPolicy e2e-tests (#527)
mikhail-aws Nov 18, 2023
f69e34c
Fix for leaking target groups on service delete (#525)
erikfuller Nov 18, 2023
ef058d0
Add missing iam policies for tags in documentation (#529)
Nov 18, 2023
aaf71da
release v1.0.0 (#528)
mikhail-aws Nov 18, 2023
c884d4b
update rbac for targetgrouppolicies and vpcassociationpolicies (#532)
mikhail-aws Nov 20, 2023
29b922b
add log level env variable and update helm (#534)
mikhail-aws Nov 21, 2023
f8d4512
Release artifacts for v1.0.1 (#537)
Nov 22, 2023
1d3c19d
Update debug mode docs (#538)
Nov 22, 2023
981ae25
Multi cluster doc improve (#533)
zijun726911 Nov 23, 2023
8c2ad0f
move controllers into pkg (#542)
mikhail-aws Nov 23, 2023
da4d2dd
Improve presubmit workflow and add docs guide (#545)
Nov 24, 2023
4935862
Make recommended-inline-policy.json content and the one shown in the …
zijun726911 Nov 28, 2023
29d740f
Add more settings in k8s yaml to prevent privileges escalation (#549)
zijun726911 Nov 30, 2023
5553213
Add service export/import documentations (#551)
Nov 30, 2023
9eafcb7
Add generic policy handler; refactor IAMAuthPolicy, TargetGroupPolicy…
mikhail-aws Nov 30, 2023
3e65856
Golangci-lint Integration first PR (#553)
zijun726911 Nov 30, 2023
5c8d161
- First step to enable Golangci-lint
Nov 29, 2023
6fcdde8
enable golangci-lint in github action and local
Nov 30, 2023
d20a94a
Address PR comments
Dec 1, 2023
c92774c
Address PR comments
Dec 1, 2023
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
27 changes: 25 additions & 2 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ on:
pull_request:
workflow_dispatch:
jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
args: --verbose --timeout 30m

presubmit:
runs-on: ubuntu-latest
strategy:
matrix:
k8sVersion: ["1.20.x", "1.21.x", "1.22.x", "1.23.x", "1.24.x"]
k8sVersion: ["1.24.x"]
env:
K8S_VERSION: ${{ matrix.k8sVersion }}
steps:
- uses: actions/checkout@v3
- run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- run: pip install -r requirements.txt
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
Expand All @@ -29,7 +49,10 @@ jobs:
~/.kubebuilder/bin
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
- run: make toolchain
- run: make presubmit
- run: make manifest
- run: make vet
- run: make test
- run: make docs
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://golangci-lint.run/usage/configuration
linters:
disable:
- errcheck
47 changes: 37 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export REGION ?= $(shell aws configure get region)
# For all targets except `help` and default target (which is also `help`), export environment variables
ifneq (,$(filter-out help,$(MAKECMDGOALS)))
export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export REGION ?= $(shell aws configure get region)
endif

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
VERSION ?= $(shell git tag --sort=v:refname | tail -1)
ECRIMAGES ?=public.ecr.aws/m7r9p7b3/aws-gateway-controller:${VERSION}
ECRIMAGES ?=public.ecr.aws/aws-application-networking-k8s/aws-gateway-controller:${VERSION}

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22
Expand Down Expand Up @@ -45,11 +49,11 @@ help: ## Display this help.

.PHONY: run
run: ## Run in development mode
go run cmd/aws-application-networking-k8s/main.go --debug
DEV_MODE=1 LOG_LEVEL=debug go run cmd/aws-application-networking-k8s/main.go


.PHONY: presubmit
presubmit: manifest vet test ## Run all commands before submitting code
presubmit: manifest vet lint test ## Run all commands before submitting code

.PHONY: vet
vet: ## Vet the code and dependencies
Expand All @@ -63,14 +67,25 @@ vet: ## Vet the code and dependencies
exit 1;\
fi;}


.PHONY: lint
lint: ## Run the golangci-lint only in local machine
if command -v golangci-lint &> /dev/null; then \
echo "Running golangci-lint"; \
golangci-lint run; \
else \
echo "Error: golangci-lint is not installed. Please run the 'make toolchain'"; \
exit 1; \
fi \


.PHONY: test
test: ## Run tests.
go test ./pkg/... ./controllers/... -coverprofile coverage.out
go test ./pkg/... -coverprofile coverage.out

.PHONY: toolchain
toolchain: ## Install developer toolchain
./hack/toolchain.sh
./scripts/gen_mocks.sh

##@ Deployment

Expand Down Expand Up @@ -99,6 +114,7 @@ e2e-test-namespace := "e2e-test"
.PHONY: e2e-test
e2e-test: ## Run e2e tests against cluster pointed to by ~/.kube/config
@kubectl create namespace $(e2e-test-namespace) > /dev/null 2>&1 || true # ignore already exists error
LOG_LEVEL=debug
cd test && go test \
-p 1 \
-count 1 \
Expand All @@ -116,3 +132,14 @@ e2e-clean: ## Delete eks resources created in the e2e test namespace
@kubectl delete namespace $(e2e-test-namespace) > /dev/null 2>&1
@kubectl create namespace $(e2e-test-namespace) > /dev/null 2>&1
@echo "Done!"

.PHONY: api-reference
api-reference: ## Update documentation in docs/api-reference.md
@cd docgen && \
gen-crd-api-reference-docs -config config.json -api-dir "../pkg/apis/applicationnetworking/v1alpha1/" -out-file docs.html && \
cat api-reference-base.md docs.html > ../docs/api-reference.md

.PHONY: docs
docs:
mkdir -p site
mkdocs build
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
# AWS Gateway API Controller for VPC Lattice

<p align="center">
<img src="docs/images/kubernetes_icon.svg" alt="Kubernetes logo" width="200" />
<img src="docs/images/controller.png" alt="AWS Load Balancer logo" width="200" />
<img src="docs/images/kubernetes_icon.svg" alt="Kubernetes logo" width="100" />
<img src="docs/images/controller.png" alt="AWS Load Balancer logo" width="100" />
</p>

AWS Application Networking is an implementation of the Kubernetes [Gateway API](https://gateway-api.sigs.k8s.io/). This project is designed to run in a Kubernetes cluster and orchestrates AWS VPC Lattice resources using Kubernetes Custom Resource Definitions like Gateway and HTTPRoute.

## Documentation

### Website

The API specification and detailed documentation is available on the project
website: [https://www.gateway-api-controller.eks.aws.dev/][ghp].

### Concepts

To get started, please read through [API concepts][concepts]. These documents give the necessary background to understand the API and the use-cases it targets.

### Getting started

Once you have a good understanding of the API at a higher-level, check out
[getting started][getting-started] to install your first Gateway controller and try out
one of the guides.

### References

A complete API reference, please refer to:

- [API reference][spec]
- [Go docs for the package][godoc]

## Contributing

Developer guide can be found on the [developer guide page][dev].
Our Kubernetes Slack channel is [#aws-gateway-api-controller][slack].

### Code of conduct

Participation in the Kubernetes community is governed by the
[Kubernetes Code of Conduct](code-of-conduct.md).

## Security

See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

## License

This project is licensed under the Apache-2.0 License.

[ghp]: https://www.gateway-api-controller.eks.aws.dev/
[dev]: https://www.gateway-api-controller.eks.aws.dev/contributing/developer/
[slack]: https://kubernetes.slack.com/messages/aws-gateway-api-controller
[getting-started]: https://www.gateway-api-controller.eks.aws.dev/guides/getstarted/
[spec]: https://www.gateway-api-controller.eks.aws.dev/api-reference/
[concepts]: https://www.gateway-api-controller.eks.aws.dev/concepts/
[gh_release]: https://github.com/aws/aws-application-networking-k8s/releases/tag/v1.0.1
[godoc]: https://www.gateway-api-controller.eks.aws.dev/
50 changes: 38 additions & 12 deletions cmd/aws-application-networking-k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"github.com/go-logr/zapr"
"go.uber.org/zap/zapcore"

"github.com/aws/aws-application-networking-k8s/pkg/aws"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
Expand All @@ -38,15 +39,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/external-dns/endpoint"
gateway_api_v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gateway_api_v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/aws/aws-application-networking-k8s/controllers"
"github.com/aws/aws-application-networking-k8s/pkg/controllers"

//+kubebuilder:scaffold:imports
anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
"github.com/aws/aws-application-networking-k8s/pkg/config"
"github.com/aws/aws-application-networking-k8s/pkg/k8s"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

var (
Expand All @@ -57,8 +60,8 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

//+kubebuilder:scaffold:scheme
utilruntime.Must(gateway_api_v1alpha2.AddToScheme(scheme))
utilruntime.Must(gateway_api_v1beta1.AddToScheme(scheme))
utilruntime.Must(gwv1alpha2.AddToScheme(scheme))
utilruntime.Must(gwv1beta1.AddToScheme(scheme))
utilruntime.Must(anv1alpha1.AddToScheme(scheme))
addOptionalCRDs(scheme)
}
Expand Down Expand Up @@ -89,17 +92,16 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var debug bool

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&debug, "debug", false, "enable debug mode")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Parse()

log := gwlog.NewLogger(debug)
logLevel := logLevel()
log := gwlog.NewLogger(logLevel)
ctrl.SetLogger(zapr.NewLogger(log.Desugar()).WithName("runtime"))

setupLog := log.Named("setup")
Expand All @@ -113,6 +115,7 @@ func main() {
"AccountId", config.AccountID,
"DefaultServiceNetwork", config.DefaultServiceNetwork,
"ClusterName", config.ClusterName,
"LogLevel", logLevel,
)

cloud, err := aws.NewCloud(log.Named("cloud"), aws.CloudConfig{
Expand All @@ -126,9 +129,13 @@ func main() {
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "amazon-vpc-lattice.io",
Expand Down Expand Up @@ -187,7 +194,12 @@ func main() {
setupLog.Fatalf("iam auth policy controller setup failed: %s", err)
}

err = controllers.RegisterVpcAssociationPolicyController(ctrlLog.Named("vpc-association-policy"), mgr, cloud)
err = controllers.RegisterTargetGroupPolicyController(ctrlLog.Named("target-group-policy"), mgr)
if err != nil {
setupLog.Fatalf("target group policy controller setup failed: %s", err)
}

err = controllers.RegisterVpcAssociationPolicyController(ctrlLog.Named("vpc-association-policy"), cloud, finalizerManager, mgr)
if err != nil {
setupLog.Fatalf("vpc association policy controller setup failed: %s", err)
}
Expand All @@ -209,3 +221,17 @@ func main() {
}

}

func logLevel() zapcore.Level {
level := os.Getenv("LOG_LEVEL")
switch level {
case "debug":
return zapcore.DebugLevel
case "error":
return zapcore.ErrorLevel
case "panic":
return zapcore.PanicLevel
default:
return zapcore.InfoLevel
}
}
2 changes: 2 additions & 0 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Code of Conduct
The AWS Gateway API Controller project follows the [CNCF Community Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ spec:
- targetRef
type: object
status:
description: TargetGroupPolicyStatus defines the observed state of AccessLogPolicy.
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: NotReconciled
status: Unknown
type: Accepted
description: Status defines the current state of TargetGroupPolicy.
properties:
conditions:
default:
Expand All @@ -171,12 +178,12 @@ spec:
reason: Pending
status: Unknown
type: Programmed
description: "Conditions describe the current conditions of the AccessLogPolicy.
description: "Conditions describe the current conditions of the TargetGroup.
\n Implementations should prefer to express Policy conditions using
the `PolicyConditionType` and `PolicyConditionReason` constants
so that operators and tools can converge on a common vocabulary
to describe AccessLogPolicy state. \n Known condition types are:
\n * \"Accepted\" * \"Ready\""
to describe TargetGroup state. \n Known condition types are: \n
* \"Accepted\" * \"Ready\""
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
Expand Down Expand Up @@ -254,4 +261,5 @@ spec:
type: object
served: true
storage: true
subresources: {}
subresources:
status: {}
Loading