From af6d0e655aec8a3e19974d7cd6f829b68cca111e Mon Sep 17 00:00:00 2001 From: Devdatta Kulkarni Date: Mon, 29 Oct 2018 14:55:00 -0500 Subject: [PATCH] Fixes for running on Minikube - IP address on Minikube starts with 192.* and not 198.* - Updating the audit log parsing method to correctly read the included static minikube audit log file --- pkg/provenance/provenance.go | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/pkg/provenance/provenance.go b/pkg/provenance/provenance.go index 4bc9a4a..14d553c 100644 --- a/pkg/provenance/provenance.go +++ b/pkg/provenance/provenance.go @@ -78,8 +78,9 @@ func init() { func onMinikube() bool { ip := os.Getenv("HOST_IP") + fmt.Printf("Minikube IP:%s\n", ip) ipBeginsWith := strings.Split(ip, ".")[0] - return ipBeginsWith == "10" || ipBeginsWith == "198" + return ipBeginsWith == "10" || ipBeginsWith == "192" //status.hostIP is set to 10.0.2.15 for onMinikube //and 127.0.0.1 for the real kubernetes server //rc.yaml @@ -91,12 +92,14 @@ func onMinikube() bool { func CollectProvenance() { fmt.Println("Inside CollectProvenance") readKindCompositionFile() + useSample := false if onMinikube() { - parse() //using a sample audit log, because + useSample = true + parse(useSample) //using a sample audit log, because //currently audit logging is not supported for minikube } else { for { //keep looping because the audit-logging is live - parse() + parse(useSample) time.Sleep(time.Second * 5) } } @@ -571,17 +574,28 @@ func (o ObjectLineage) FieldDiff(fieldName string, vNumStart, vNumEnd int) strin } //Ref:https://www.sohamkamani.com/blog/2017/10/18/parsing-json-in-golang/#unstructured-data -func parse() { +func parse(useSample bool) { - if _, err := os.Stat("/tmp/kube-apiserver-audit.log"); os.IsNotExist(err) { - fmt.Println(fmt.Sprintf("could not stat the path %s", err)) + var log *os.File + var err error + if useSample { + log, err = os.Open("/tmp/minikube-sample-audit.log") + if err != nil { + fmt.Println(fmt.Sprintf("could not open the log file %s", err)) panic(err) - } - log, err := os.Open("/tmp/kube-apiserver-audit.log") - if err != nil { + } + } else { + if _, err := os.Stat("/tmp/kube-apiserver-audit.log"); os.IsNotExist(err) { + fmt.Println(fmt.Sprintf("could not stat the path %s", err)) + panic(err) + } + log, err = os.Open("/tmp/kube-apiserver-audit.log") + if err != nil { fmt.Println(fmt.Sprintf("could not open the log file %s", err)) panic(err) + } } + defer log.Close() scanner := bufio.NewScanner(log)