-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add watch-namespaces option (#13)
* feat: add --watch-namespaces option * fix: push image from pr WIP
- Loading branch information
Showing
8 changed files
with
146 additions
and
30 deletions.
There are no files selected for viewing
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,54 @@ | ||
name: Run tests and push image | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
GO_VERSION: '1.20' | ||
REGISTRY: ghcr.io | ||
IMAGE: ghcr.io/${{ github.repository }} | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: install go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: run tests | ||
run: make test | ||
|
||
push-image: | ||
runs-on: ubuntu-latest | ||
needs: run-tests | ||
permissions: | ||
packages: write | ||
|
||
steps: | ||
- name: Install make | ||
run: sudo apt-get install -y make | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: build | ||
run: make release | ||
env: | ||
IMAGE: ${{ env.IMAGE }} | ||
version: pr-13 | ||
#version: ${{ github.ref_name }} |
File renamed without changes.
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,22 @@ | ||
package predicates | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
) | ||
|
||
func NamespaceFilter(namespaces []string) predicate.Predicate { | ||
return predicate.NewPredicateFuncs(func(object client.Object) bool { | ||
// No filter specified | ||
if len(namespaces) == 0 || len(namespaces) == 1 && namespaces[0] == "" { | ||
return true | ||
} | ||
|
||
for _, ns := range namespaces { | ||
if ns == object.GetNamespace() { | ||
return true | ||
} | ||
} | ||
return false | ||
}) | ||
} |
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,44 @@ | ||
package predicates | ||
|
||
import ( | ||
"testing" | ||
|
||
crdv1beta1 "github.com/inovex/aws-auth-controller/pkg/api/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
//+kubebuilder:scaffold:imports | ||
) | ||
|
||
// These tests use Ginkgo (BDD-style Go testing framework). Refer to | ||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. | ||
|
||
func TestPredicates(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
|
||
RunSpecs(t, "Predicates Suite") | ||
} | ||
|
||
var _ = Context("Predicates", func() { | ||
Describe("namespaceFilter", func() { | ||
DescribeTable("filter for namespaces", func(namespace string, watched []string, result bool) { | ||
obj := &crdv1beta1.AwsAuthMapSnippet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo-bar", | ||
Namespace: namespace, | ||
}, | ||
} | ||
pred := NamespaceFilter(watched) | ||
Expect(pred.Create(event.CreateEvent{Object: obj})).To(Equal(result)) | ||
}, | ||
Entry("with no filter", "anyns", []string{}, true), | ||
Entry("with empty filter", "anyns", []string{""}, true), | ||
Entry("with single filter", "myns", []string{"myns"}, true), | ||
Entry("with single filter skipped", "anyns", []string{"myns"}, false), | ||
Entry("with multiple filter", "myns", []string{"myns", "otherns"}, true), | ||
Entry("with multple filter skipped", "anyns", []string{"myns", "otherns"}, false), | ||
) | ||
}) | ||
}) |