Skip to content

Commit

Permalink
I fixed types.go, readded kind_compositions because need the kindMap …
Browse files Browse the repository at this point in the history
…for the rest api endpoints, and now I'm getting a problem with how my container is built. cannot panic: stat kube-apiserver-audit.log: no such file or directory
  • Loading branch information
djarotech committed Aug 10, 2018
1 parent 09aa748 commit 518ff9d
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 491 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions artifacts/simple-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
# limitations under the License.

FROM fedora
RUN mkdir -p /tmp/
ADD kube-provenance-apiserver /
ADD kube-apiserver-audit.log /tmp/
ENTRYPOINT ["/kube-provenance-apiserver"]
6 changes: 6 additions & 0 deletions artifacts/simple-image/kube-apiserver-audit.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"kind":"Event","apiVersion":"audit.k8s.io/v1beta1","metadata":{"creationTimestamp":"2018-08-05T00:16:20Z"},"level":"Request","timestamp":"2018-08-05T00:16:20Z","auditID":"99b27a2b-e320-4ca7-94bf-9a3a080cb2f2","stage":"ResponseComplete","requestURI":"/apis/postgrescontroller.kubeplus/v1/namespaces/default/postgreses","verb":"create","user":{"username":"system:admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["127.0.0.1"],"userAgent":"kubectl/v1.12.0 (linux/amd64) kubernetes/f1b6611","objectRef":{"resource":"postgreses","namespace":"default","apiGroup":"postgrescontroller.kubeplus","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":201},"requestObject":{"apiVersion":"postgrescontroller.kubeplus/v1","kind":"Postgres","metadata":{"creationTimestamp":null,"name":"client25","namespace":"default"},"spec":{"databases":["moodle"],"deploymentName":"client25","image":"postgres:9.3","initcommands":["\\c moodle;","create table moodle_data1 (items varchar(250));","insert into moodle_data1 (items) values ('Moodle data1');","insert into moodle_data1 (items) values ('Moodle data1');","insert into moodle_data1 (items) values ('Moodle data2');","GRANT ALL PRIVILEGES ON TABLE moodle_data1 TO devdatta;","GRANT ALL PRIVILEGES ON TABLE moodle_data1 TO pallavi;"],"replicas":1,"users":[{"password":"pass123","username":"devdatta"},{"password":"pass234","username":"pallavi"}]}},"requestReceivedTimestamp":"2018-08-05T00:16:20.176744Z","stageTimestamp":"2018-08-05T00:16:20.180766Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}
{"kind":"Event","apiVersion":"audit.k8s.io/v1beta1","metadata":{"creationTimestamp":"2018-08-05T00:16:46Z"},"level":"Request","timestamp":"2018-08-05T00:16:46Z","auditID":"e20539e0-d8a6-40b8-88e0-2592f1f4ac0c","stage":"ResponseComplete","requestURI":"/apis/postgrescontroller.kubeplus/v1/namespaces/default/postgreses/client25","verb":"patch","user":{"username":"system:admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["127.0.0.1"],"userAgent":"kubectl/v1.12.0 (linux/amd64) kubernetes/f1b6611","objectRef":{"resource":"postgreses","namespace":"default","name":"client25","apiGroup":"postgrescontroller.kubeplus","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":200},"requestObject":{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"postgrescontroller.kubeplus/v1\",\"kind\":\"Postgres\",\"metadata\":{\"annotations\":{},\"name\":\"client25\",\"namespace\":\"default\"},\"spec\":{\"databases\":[\"moodle\",\"wordpress\",\"ecommerce\"],\"deploymentName\":\"client25\",\"image\":\"postgres:9.3\",\"replicas\":1,\"users\":[{\"password\":\"pass123\",\"username\":\"devdatta\"},{\"password\":\"pass234\",\"username\":\"pallavi\"}]}}\n"}},"spec":{"databases":["moodle","wordpress","ecommerce"]}},"requestReceivedTimestamp":"2018-08-05T00:16:46.921618Z","stageTimestamp":"2018-08-05T00:16:46.923885Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}
{"kind":"Event","apiVersion":"audit.k8s.io/v1beta1","metadata":{"creationTimestamp":"2018-08-05T00:16:51Z"},"level":"Request","timestamp":"2018-08-05T00:16:51Z","auditID":"68551497-6eca-4d6a-afc7-16d5909bfd78","stage":"ResponseComplete","requestURI":"/apis/postgrescontroller.kubeplus/v1/namespaces/default/postgreses/client25","verb":"patch","user":{"username":"system:admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["127.0.0.1"],"userAgent":"kubectl/v1.12.0 (linux/amd64) kubernetes/f1b6611","objectRef":{"resource":"postgreses","namespace":"default","name":"client25","apiGroup":"postgrescontroller.kubeplus","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":200},"requestObject":{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"postgrescontroller.kubeplus/v1\",\"kind\":\"Postgres\",\"metadata\":{\"annotations\":{},\"name\":\"client25\",\"namespace\":\"default\"},\"spec\":{\"databases\":[\"moodle\",\"wordpress\"],\"deploymentName\":\"client25\",\"image\":\"postgres:9.3\",\"replicas\":1,\"users\":[{\"password\":\"pass123\",\"username\":\"devdatta\"},{\"password\":\"pass234\",\"username\":\"pallavi\"}]}}\n"}},"spec":{"databases":["moodle","wordpress"]}},"requestReceivedTimestamp":"2018-08-05T00:16:51.839690Z","stageTimestamp":"2018-08-05T00:16:51.841691Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}
{"kind":"Event","apiVersion":"audit.k8s.io/v1beta1","metadata":{"creationTimestamp":"2018-08-05T00:17:12Z"},"level":"Request","timestamp":"2018-08-05T00:17:12Z","auditID":"fa44d2d5-f13e-4ff3-8e32-f4e693546f7a","stage":"ResponseComplete","requestURI":"/apis/postgrescontroller.kubeplus/v1/namespaces/default/postgreses/client25","verb":"patch","user":{"username":"system:admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["127.0.0.1"],"userAgent":"kubectl/v1.12.0 (linux/amd64) kubernetes/f1b6611","objectRef":{"resource":"postgreses","namespace":"default","name":"client25","apiGroup":"postgrescontroller.kubeplus","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":200},"requestObject":{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"postgrescontroller.kubeplus/v1\",\"kind\":\"Postgres\",\"metadata\":{\"annotations\":{},\"name\":\"client25\",\"namespace\":\"default\"},\"spec\":{\"databases\":[\"moodle\",\"wordpress\"],\"deploymentName\":\"client25\",\"image\":\"postgres:9.3\",\"replicas\":1,\"users\":[{\"password\":\"pass123\",\"username\":\"devdatta\"},{\"password\":\"pass234\",\"username\":\"pallavi\"},{\"password\":\"pass1\",\"username\":\"shrinivas\"}]}}\n"}},"spec":{"users":[{"password":"pass123","username":"devdatta"},{"password":"pass234","username":"pallavi"},{"password":"pass1","username":"shrinivas"}]}},"requestReceivedTimestamp":"2018-08-05T00:17:12.759670Z","stageTimestamp":"2018-08-05T00:17:12.761817Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}
{"kind":"Event","apiVersion":"audit.k8s.io/v1beta1","metadata":{"creationTimestamp":"2018-08-05T00:17:20Z"},"level":"Request","timestamp":"2018-08-05T00:17:20Z","auditID":"0edc056d-c370-4f29-b41c-ee584fc54c53","stage":"ResponseComplete","requestURI":"/apis/postgrescontroller.kubeplus/v1/namespaces/default/postgreses/client25","verb":"patch","user":{"username":"system:admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["127.0.0.1"],"userAgent":"kubectl/v1.12.0 (linux/amd64) kubernetes/f1b6611","objectRef":{"resource":"postgreses","namespace":"default","name":"client25","apiGroup":"postgrescontroller.kubeplus","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":200},"requestObject":{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"postgrescontroller.kubeplus/v1\",\"kind\":\"Postgres\",\"metadata\":{\"annotations\":{},\"name\":\"client25\",\"namespace\":\"default\"},\"spec\":{\"databases\":[\"moodle\",\"wordpress\"],\"deploymentName\":\"client25\",\"image\":\"postgres:9.3\",\"replicas\":1,\"users\":[{\"password\":\"pass123\",\"username\":\"devdatta\"},{\"password\":\"pass234\",\"username\":\"pallavi\"}]}}\n"}},"spec":{"users":[{"password":"pass123","username":"devdatta"},{"password":"pass234","username":"pallavi"}]}},"requestReceivedTimestamp":"2018-08-05T00:17:20.526592Z","stageTimestamp":"2018-08-05T00:17:20.528723Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}
{"kind":"Event","apiVersion":"audit.k8s.io/v1beta1","metadata":{"creationTimestamp":"2018-08-05T00:17:26Z"},"level":"Request","timestamp":"2018-08-05T00:17:26Z","auditID":"cf460fc3-a11a-4b8f-a393-5ae60f7d662b","stage":"ResponseComplete","requestURI":"/apis/postgrescontroller.kubeplus/v1/namespaces/default/postgreses/client25","verb":"patch","user":{"username":"system:admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["127.0.0.1"],"userAgent":"kubectl/v1.12.0 (linux/amd64) kubernetes/f1b6611","objectRef":{"resource":"postgreses","namespace":"default","name":"client25","apiGroup":"postgrescontroller.kubeplus","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":200},"requestObject":{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"postgrescontroller.kubeplus/v1\",\"kind\":\"Postgres\",\"metadata\":{\"annotations\":{},\"name\":\"client25\",\"namespace\":\"default\"},\"spec\":{\"databases\":[\"moodle\",\"wordpress\"],\"deploymentName\":\"client25\",\"image\":\"postgres:9.3\",\"replicas\":1,\"users\":[{\"password\":\"pass123\",\"username\":\"devdatta\"},{\"password\":\"pass123\",\"username\":\"pallavi\"}]}}\n"}},"spec":{"users":[{"password":"pass123","username":"devdatta"},{"password":"pass123","username":"pallavi"}]}},"requestReceivedTimestamp":"2018-08-05T00:17:26.047828Z","stageTimestamp":"2018-08-05T00:17:26.049674Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}
2 changes: 0 additions & 2 deletions build-provenance-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
export GOOS=linux; go build .
cp kubeprovenance ./artifacts/simple-image/kube-provenance-apiserver
docker build -t kube-provenance-apiserver:latest ./artifacts/simple-image


36 changes: 19 additions & 17 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"strings"

"github.com/emicklei/go-restful"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/version"
genericapiserver "k8s.io/apiserver/pkg/server"
"github.com/emicklei/go-restful"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"

utilruntime "k8s.io/apimachinery/pkg/util/runtime"

Expand All @@ -21,11 +21,11 @@ const GroupName = "kubeprovenance.cloudark.io"
const GroupVersion = "v1"

var (
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion}
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion}
)

func addKnownTypes(scheme *runtime.Scheme) error {
Expand All @@ -40,7 +40,7 @@ func init() {
utilruntime.Must(Scheme.SetVersionPriority(SchemeGroupVersion))

// TODO(devdattakulkarni) -- Following comments coming from sample-apiserver.
// Leaving them for now.
// Leaving them for now.
// we need to add the options to empty v1
// TODO fix the server code to avoid this
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: GroupVersion})
Expand Down Expand Up @@ -191,12 +191,15 @@ func getHistory(request *restful.Request, response *restful.Response) {
// /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/dep1/compositions
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice
// provenanceInfo := provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)
// provenanceInfo := provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)

provenanceInfo := "Resource Name:" + resourceName + " Resource Kind:" + resourceKind
fmt.Println(provenanceInfo)

response.Write([]byte(provenanceInfo))
specStrings := provenance.ObjectFullProvenance.SpecHistory()
for _, str := range specStrings {
response.Write([]byte(str))
}

}

func bisect(request *restful.Request, response *restful.Response) {
Expand All @@ -210,7 +213,7 @@ func bisect(request *restful.Request, response *restful.Response) {
// /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/dep1/compositions
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice

var provenanceInfo string
//provenanceInfo = provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)
provenanceInfo = "Resource Name:" + resourceName + " Resource Kind:" + resourceKind
Expand All @@ -219,14 +222,13 @@ func bisect(request *restful.Request, response *restful.Response) {
field := request.QueryParameter("field")
value := request.QueryParameter("value")

provenanceInfo = provenanceInfo + " Field:" + field + " Value:" + value
provenanceInfo = provenanceInfo + " Field:" + field + " Value:" + value

fmt.Println("ProvenanceInfo:%v", provenanceInfo)

response.Write([]byte(provenanceInfo))
}


func getDiff(request *restful.Request, response *restful.Response) {
fmt.Println("Inside getDiff")
resourceName := request.PathParameter("resource-id")
Expand All @@ -244,7 +246,7 @@ func getDiff(request *restful.Request, response *restful.Response) {
field := request.QueryParameter("field")

var diffInfo string
if ( start == "" || end == "" ) {
if start == "" || end == "" {
fmt.Println("Start:%s", start)
fmt.Println("End:%s", end)
diffInfo = "start and end query parameters missing\n"
Expand All @@ -259,4 +261,4 @@ func getDiff(request *restful.Request, response *restful.Response) {
diffInfo = "This is Diff Info: " + start + " " + end + " " + field
}
response.Write([]byte(diffInfo))
}
}
Loading

0 comments on commit 518ff9d

Please sign in to comment.