-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: rewrite and cleanup kubenurse server code (#29)
* refactor!: rewrite and cleanup kubenurse server code By using a package and multiple separate files the code is easier to understand and test. A new /ready handler was added so we can configure a readiness probe to allow seamless updates of kubenurse. * build: update golangci-lint version * build: update golangci-lint timeout, default is too short * build: extract lint step and use go version 1.17 * feat: configure new readinessprobe in kustomize and helm templates * fix: linter errors * chore: cleanup, remove not needed WaitGroup * refactor!: move pkg/kubediscovery to internal/kubediscovery * refactor!: move pkg/checker to internal/servicecheck * refactor!: incorporate pkg/metrics in internal/servicecheck * refactor!: more refactorings to allow easier unit testing * feat: more unit tests and coverage calculation in workflows * docs: include ci and coverage badges in readme * docs: fix coverage status URL Co-authored-by: Clément Nussbaumer <[email protected]> * chore: embed servicecheck.Result in /alive output for simplicity Co-authored-by: Clément Nussbaumer <[email protected]>
- Loading branch information
1 parent
50fb9eb
commit 7beac30
Showing
26 changed files
with
788 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
name: lint and test | ||
on: | ||
push: | ||
pull_request: | ||
jobs: | ||
lint-go: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.43 | ||
args: --timeout 5m | ||
lint-helm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Helm lint | ||
shell: bash | ||
run: | | ||
helm lint ./helm/kubenurse/ | ||
test-go: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
- name: Run unit tests | ||
run: go test -race -covermode atomic -coverprofile=profile.cov ./... | ||
- name: Send coverage report | ||
env: | ||
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
go install github.com/mattn/[email protected] | ||
goveralls -coverprofile=profile.cov -service=github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kubediscovery | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
var ( | ||
kubenursePod = v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "kubenurse-dummy", | ||
Labels: map[string]string{ | ||
"app": "kubenurse", | ||
}, | ||
}, | ||
} | ||
differentPod = v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "different", | ||
Labels: map[string]string{ | ||
"app": "different", | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func TestGetNeighbours(t *testing.T) { | ||
r := require.New(t) | ||
fakeClient := fake.NewSimpleClientset() | ||
|
||
createFakePods(fakeClient) | ||
|
||
client, err := New(context.Background(), fakeClient, false) | ||
r.NoError(err) | ||
|
||
neighbours, err := client.GetNeighbours(context.Background(), "kube-system", "app=kubenurse") | ||
r.NoError(err) | ||
r.Len(neighbours, 1) | ||
r.Equal(kubenursePod.ObjectMeta.Name, neighbours[0].PodName) | ||
} | ||
|
||
func createFakePods(k8s kubernetes.Interface) { | ||
for _, pod := range []v1.Pod{kubenursePod, differentPod} { | ||
_, err := k8s.CoreV1().Pods("kube-system").Create(context.Background(), &pod, metav1.CreateOptions{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.