Skip to content

Commit

Permalink
tested access to cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
hccheng72 committed Apr 8, 2022
1 parent 45a433e commit 39de770
Show file tree
Hide file tree
Showing 3 changed files with 443 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/tool/az-analyze/cmd/azv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ limitations under the License.
package cmd

import (
"context"
"flag"
"fmt"
"os"
"path/filepath"

//"reflect"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
v1beta1 "sigs.k8s.io/azuredisk-csi-driver/pkg/apis/azuredisk/v1beta1"
//azDiskClientSet "sigs.k8s.io/azuredisk-csi-driver/pkg/apis/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
//consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
)

// azvCmd represents the azv command
Expand Down Expand Up @@ -77,6 +87,44 @@ type AzvResource struct {

func GetAzVolumesByPod(podNames []string) []AzvResource {
// implemetation
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()

config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
} else {
pods, err := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err.Error())
}
fmt.Println(len(pods.Items))
}



// clientset, err := azDiskClientSet.NewForConfig(config)
// if err != nil {
// panic(err.Error())
// } else {
// azVolumeset, err := clientset.DiskV1beta1().AzVolumeAttachments("azure-disk-csi").List(context.Background(), metav1.ListOptions{})
// if err != nil {
// panic(err.Error())

// }
// fmt.Println(len(azVolumeset.Items))
// }

var result []AzvResource
result = append(result, AzvResource {
ResourceType: "example-pod-123",
Expand Down
14 changes: 14 additions & 0 deletions pkg/tool/az-analyze/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.10.1
k8s.io/client-go v0.23.3
sigs.k8s.io/azuredisk-csi-driver v1.14.1-0.20220406220237-37935413efe1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.5 // indirect
Expand All @@ -31,14 +36,23 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // 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/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.23.3 // indirect
k8s.io/apimachinery v0.23.5 // indirect
k8s.io/klog/v2 v2.40.1 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 39de770

Please sign in to comment.