Skip to content

Commit

Permalink
feat: add kubernetes client
Browse files Browse the repository at this point in the history
  • Loading branch information
Azhovan committed Oct 9, 2023
1 parent 516bef9 commit f402a6d
Show file tree
Hide file tree
Showing 5 changed files with 593 additions and 13 deletions.
45 changes: 45 additions & 0 deletions apptests/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Package client provides a client for interacting with Kubernetes clusters.
// It wraps the kubernetes client-go library and exposes a simple interface
// for creating and using a kubernetes client.
package client

import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

type Client struct {
config *rest.Config
clientset *kubernetes.Clientset
}

// NewClient creates a new kubernetes client.
func NewClient(kubeconfigPath string) (*Client, error) {
// build the config from the kubeconfig path
conf, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
return nil, err
}

// create the clientset with the config and the context
clientset, err := kubernetes.NewForConfig(conf)
if err != nil {
return nil, err
}

return &Client{
config: conf,
clientset: clientset,
}, nil
}

// Config returns the client config.
func (c *Client) Config() *rest.Config {
return c.config
}

// Clientset returns the kubernetes clientset.
func (c *Client) Clientset() *kubernetes.Clientset {
return c.clientset
}
56 changes: 56 additions & 0 deletions apptests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module github.com/mesosphere/kommander-applications/apptests

go 1.20

require k8s.io/client-go v0.27.4

require (
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/onsi/gomega v1.27.10 // indirect
golang.org/x/tools v0.13.0 // indirect
k8s.io/api v0.27.4 // indirect
k8s.io/apimachinery v0.27.4 // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // 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
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit f402a6d

Please sign in to comment.