Skip to content

Commit dd7bc8c

Browse files
Merge pull request #11 from gwesterfieldjr/repo-improvements
add readme and linter to verify any missing nil checks
2 parents 8d08273 + 5f8096e commit dd7bc8c

File tree

7 files changed

+69
-6
lines changed

7 files changed

+69
-6
lines changed

.github/workflows/golangci-lint.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- main
8+
pull_request:
9+
jobs:
10+
golangci:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-go@v3
16+
with:
17+
go-version: '1.18'
18+
check-latest: true
19+
cache: true
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v3
22+
with:
23+
version: v1.49.0

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ generate-conversion: $(CONVERSION_GEN)
8181
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
8282
--go-header-file=hack/boilerplate.go.txt
8383

84+
build: docker-build
85+
8486
# Build the docker image
8587
docker-build: test
8688
docker build . -t ${IMG}
@@ -89,6 +91,19 @@ docker-build: test
8991
docker-push:
9092
docker push ${IMG}
9193

94+
.PHONY: lint
95+
lint: bin/golangci-lint ## Run golangci-lint
96+
bin/golangci-lint run
97+
98+
bin/golangci-lint: ## Download golangci-lint
99+
bin/golangci-lint: GOLANGCI_LINT_VERSION?=$(shell cat .github/workflows/golangci-lint.yml | yq e '.jobs.golangci.steps[] | select(.name == "golangci-lint") .with.version' -)
100+
bin/golangci-lint:
101+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
102+
103+
.PHONY: clean
104+
clean:
105+
rm -Rf ./bin
106+
92107
$(CONTROLLER_GEN): $(TOOLS_BIN_DIR) # Build controller-gen from tools folder.
93108
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
94109

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## ETCD Admin Controller for Amazon EKS Anywhere
2+
3+
The etcdadm-controller is responsible for managing external etcd clusters created by Amazon EKS Anywhere (EKS-A)
4+
5+
Amazon EKS Anywhere is a new deployment option for Amazon EKS that enables you to easily create and operate Kubernetes clusters on-premises with your own virtual machines.
6+
It brings a consistent AWS management experience to your data center, building on the strengths of [Amazon EKS Distro](https://github.com/aws/eks-distro), the same distribution of Kubernetes that powers EKS on AWS.
7+
Its goal is to include full lifecycle management of multiple Kubernetes clusters that are capable of operating completely independently of any AWS services.
8+
9+
Here are the steps for [getting started](https://anywhere.eks.amazonaws.com/docs/getting-started/) with EKS Anywhere.
10+
Full documentation for releases can be found on [https://anywhere.eks.amazonaws.com](https://anywhere.eks.amazonaws.com/).
11+
12+
## Security
13+
14+
If you discover a potential security issue in this project, or think you may
15+
have discovered a security issue, we ask that you notify AWS Security via our
16+
[vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/).
17+
Please do **not** create a public GitHub issue.
18+
19+
## License
20+
21+
This project is licensed under the [Apache-2.0 License](LICENSE).

controllers/controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (r *EtcdadmClusterReconciler) reconcile(ctx context.Context, etcdCluster *e
252252
if nextMachineUpdateTime.After(time.Now()) {
253253
// the latest machine with updated spec should get more time for etcd data sync
254254
// requeue this after
255-
after := nextMachineUpdateTime.Sub(time.Now())
255+
after := time.Until(nextMachineUpdateTime)
256256
log.Info(fmt.Sprintf("Requeueing etcdadm cluster for updating next machine after %s", after.String()))
257257
return ctrl.Result{RequeueAfter: after}, nil
258258
}
@@ -276,7 +276,8 @@ func (r *EtcdadmClusterReconciler) reconcile(ctx context.Context, etcdCluster *e
276276
if conditions.Has(ep.EC, etcdv1.EtcdMachinesSpecUpToDateCondition) {
277277
conditions.MarkTrue(ep.EC, etcdv1.EtcdMachinesSpecUpToDateCondition)
278278

279-
if _, hasUpgradeAnnotation := etcdCluster.Annotations[etcdv1.UpgradeInProgressAnnotation]; hasUpgradeAnnotation {
279+
_, hasUpgradeAnnotation := etcdCluster.Annotations[etcdv1.UpgradeInProgressAnnotation]
280+
if hasUpgradeAnnotation {
280281
delete(etcdCluster.Annotations, etcdv1.UpgradeInProgressAnnotation)
281282
}
282283
}

controllers/healthcheck.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"crypto/x509"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net"
1111
"net/http"
1212
"net/url"
@@ -65,7 +65,7 @@ func (r *EtcdadmClusterReconciler) performEndpointHealthCheck(ctx context.Contex
6565
// reuse connection
6666
defer resp.Body.Close()
6767

68-
body, err := ioutil.ReadAll(resp.Body)
68+
body, err := io.ReadAll(resp.Body)
6969
if err != nil {
7070
return err
7171
}

controllers/periodic_healthcheck.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func (r *EtcdadmClusterReconciler) periodicEtcdMembersHealthCheck(ctx context.Co
135135
}
136136
} else {
137137
// member passed healthcheck. so if it was previously added to unhealthy map, remove it since only consecutive failures should lead to member removal
138-
if _, markedUnhealthy := currClusterHFConfig.unhealthyMembersFrequency[endpoint]; markedUnhealthy {
138+
_, markedUnhealthy := currClusterHFConfig.unhealthyMembersFrequency[endpoint]
139+
if markedUnhealthy {
139140
delete(currClusterHFConfig.unhealthyMembersFrequency, endpoint)
140141
}
141142
}

main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ func main() {
107107
var onlyOneSignalHandler = make(chan struct{})
108108
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}
109109

110-
/* Controller runtime 0.5.4 returns a stop channel and 0.7.0 onwards returns a context that can be passed down to SetupWithManager and reconcilers
110+
/*
111+
Controller runtime 0.5.4 returns a stop channel and 0.7.0 onwards returns a context that can be passed down to SetupWithManager and reconcilers
112+
111113
Because cluster-api v0.3.x uses controller-runtime 0.5.4 version, etcdadm-controller cannot switch to a higher controller-runtime due to version mismatch errors
112114
So this function setupSignalHandler is a modified version of controller-runtime's SetupSignalHandler that returns both, a stop channel and a context that
113115
is cancelled when this controller exits

0 commit comments

Comments
 (0)