Skip to content

Instantly share code, notes, and snippets.

@udryan10
Last active October 4, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udryan10/5ce6d1c0ed86ad9cc476f491eff99f67 to your computer and use it in GitHub Desktop.
Save udryan10/5ce6d1c0ed86ad9cc476f491eff99f67 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"k8s.io/client-go/1.4/kubernetes/fake"
"k8s.io/client-go/1.4/pkg/api"
)
/*
Issue:
Despite passing a service into fake.NewSimpleClientset(), I am never able to retrieve that object when doing: fakeClient.Core().Services("").Get("")
The code below is a working example of the problem
*/
func main() {
services :=
&api.Service{
ObjectMeta: api.ObjectMeta{
Name: "test",
Labels: map[string]string{
"foo": "bar",
},
Namespace: "test1",
},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
api.ServicePort{
Port: 80,
},
},
},
}
fakeClient := fake.NewSimpleClientset(services)
service, err := fakeClient.Core().Services("test1").Get("test")
// this constantly returns:
// error: Service "test" not found
if err != nil {
fmt.Println("error: ", err)
return
}
fmt.Println(service)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment