Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Jul 31, 2022
1 parent 8dd4a05 commit 2b3fe5c
Show file tree
Hide file tree
Showing 13 changed files with 977 additions and 15 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test conformance

on: pull_request

jobs:
create-cluster:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-

- name: Build Go binary
run: |
cd ./conformance
go build -ldflags "-s -w" -o conformance .
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./conformance
tags: ghcr.io/castai/k8s-client-go/conformance:${{ github.sha }}

- name: Create k8s cluster
uses: helm/kind-action@v1.3.0

- name: Run conformance
run: |
cd ./conformance
./run.sh
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.idea
kuberesolver.iml
conformance/bin
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# k8s-client-go

Minimal Go Kubernetes client based on github.com/sercand/kuberesolver
Minimal Go Kubernetes client
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ func Watch[T Object](kc *Client, ctx context.Context, reqURL string, _ ListOptio
return newStreamWatcher[T](resp.Body, kc.Logger, kc.ResponseDecoderFunc(resp.Body)), nil
}

func GetEndpoints(kc *Client, ctx context.Context, namespace, targetName string, opts GetOptions) (Endpoints, error) {
reqURL := fmt.Sprintf("%s/api/v1/namespaces/%s/endpoints/%s", kc.Host, namespace, targetName)
return Get[Endpoints](kc, ctx, reqURL, opts)
func GetEndpoints(kc *Client, ctx context.Context, namespace, name string, opts GetOptions) (*Endpoints, error) {
reqURL := fmt.Sprintf("%s/api/v1/namespaces/%s/endpoints/%s", kc.Host, namespace, name)
return Get[*Endpoints](kc, ctx, reqURL, opts)
}

func WatchEndpoints(kc *Client, ctx context.Context, namespace, targetName string, _ ListOptions) (WatchInterface[Endpoints], error) {
u, err := url.Parse(fmt.Sprintf("%s/api/v1/watch/namespaces/%s/endpoints/%s", kc.Host, namespace, targetName))
func WatchEndpoints(kc *Client, ctx context.Context, namespace, name string, _ ListOptions) (WatchInterface[*Endpoints], error) {
u, err := url.Parse(fmt.Sprintf("%s/api/v1/watch/namespaces/%s/endpoints/%s", kc.Host, namespace, name))
if err != nil {
return nil, err
}
Expand All @@ -194,7 +194,7 @@ func WatchEndpoints(kc *Client, ctx context.Context, namespace, targetName strin
if resp.StatusCode != http.StatusOK {
defer resp.Body.Close()
errmsg, _ := ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf("invalid response code %d for service %s in namespace %s: %s", resp.StatusCode, targetName, namespace, string(errmsg))
return nil, fmt.Errorf("invalid response code %d for service %s in namespace %s: %s", resp.StatusCode, name, namespace, string(errmsg))
}
return newStreamWatcher[Endpoints](resp.Body, kc.Logger, kc.ResponseDecoderFunc(resp.Body)), nil
return newStreamWatcher[*Endpoints](resp.Body, kc.Logger, kc.ResponseDecoderFunc(resp.Body)), nil
}
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func ExampleClient() {
}

ctx := context.Background()
endpoints, err := client.GetEndpoints(kc, ctx, "kube-system", "kubelet")
endpoints, err := client.GetEndpoints(kc, ctx, "kube-system", "kubelet", client.GetOptions{})
if err != nil {
// Handle err
}
Expand Down
3 changes: 3 additions & 0 deletions conformance/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.13
COPY bin/conformance /usr/local/bin/conformance
CMD ["/usr/local/bin/conformance"]
52 changes: 52 additions & 0 deletions conformance/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module conformance

go 1.18

require (
github.com/castai/k8s-client-go v0.0.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
k8s.io/api v0.24.3
k8s.io/apimachinery v0.24.3
k8s.io/client-go v0.24.3
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/castai/k8s-client-go v0.0.0 => ../
Loading

0 comments on commit 2b3fe5c

Please sign in to comment.