Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the config retreival mechanism #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sentryflow/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ clean:

.PHONY: run
run:
docker run -it --rm $(IMAGE_NAME):$(TAG)
# docker run -it --rm $(IMAGE_NAME):$(TAG)
go run main.go

.PHONY: gofmt
gofmt:
Expand Down
37 changes: 31 additions & 6 deletions sentryflow/core/k8sHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ package core

import (
"context"
"flag"
"log"
"path/filepath"
"sync"
"time"

"github.com/5GSEC/sentryflow/config"
"github.com/5GSEC/sentryflow/types"
"gopkg.in/yaml.v2"
Expand All @@ -13,9 +19,8 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"log"
"sync"
"time"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)

// K8s global reference for Kubernetes Handler
Expand Down Expand Up @@ -54,9 +59,29 @@ func (kh *K8sHandler) InitK8sClient() bool {
var err error

// Initialize in cluster config
kh.config, err = rest.InClusterConfig()
// kh.config, err = rest.InClusterConfig()
// if err != nil {
// return false
// }

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
kh.config, err = clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
return false
log.Printf("Building config from flags failed, %s, trying to build inclusterconfig", err.Error())
kh.config, err = rest.InClusterConfig()
if err != nil {
log.Printf("error %s building inclusterconfig", err.Error())
return false
}
}

// Initialize Kubernetes clientSet
Expand Down Expand Up @@ -391,7 +416,7 @@ func (kh *K8sHandler) PatchIstioConfigMap() error {

// Append eps to the existing slice
if !duplicate {
meshConfig["extensionProviders"] = append(ep.([]map[interface{}]interface{}), eps)
meshConfig["extensionProviders"] = append(ep.([]interface{}), eps)
}
}

Expand Down
Loading