func resourceLocationHelper(buildStatus api.BuildStatus, podPhase string, ctx kapi.Context) (string, error) { expectedBuild := mockBuild(buildStatus, podPhase) buildRegistry := test.BuildRegistry{Build: expectedBuild} storage := REST{ BuildRegistry: &buildRegistry, PodGetter: &testPodGetter{}, ConnectionInfo: &kclient.HTTPKubeletClient{EnableHttps: true, Port: 12345, Client: &http.Client{}}, Timeout: defaultTimeout, } getter := rest.GetterWithOptions(&storage) obj, err := getter.Get(ctx, "foo-build", &api.BuildLogOptions{NoWait: true}) if err != nil { return "", err } streamer, ok := obj.(*genericrest.LocationStreamer) if !ok { return "", fmt.Errorf("Result of get not LocationStreamer") } if streamer.Location != nil { return streamer.Location.String(), nil } return "", nil }
type StatusREST struct { store *etcdgeneric.Etcd } // New creates a new pod resource func (r *StatusREST) New() runtime.Object { return &api.Pod{} } // Update alters the status subset of an object. func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) { return r.store.Update(ctx, obj) } // Implement GetterWithOptions var _ = rest.GetterWithOptions(&LogREST{}) // LogREST implements the log endpoint for a Pod type LogREST struct { store *etcdgeneric.Etcd kubeletConn client.ConnectionInfoGetter } // LogREST implements GetterWithOptions var _ = rest.GetterWithOptions(&LogREST{}) // New creates a new Pod log options object func (r *LogREST) New() runtime.Object { // TODO - return a resource that represents a log return &api.Pod{} }
const defaultTimeout time.Duration = 10 * time.Second // NewREST creates a new REST for BuildLog // Takes build registry and pod client to get necessary attributes to assemble // URL to which the request shall be redirected in order to get build logs. func NewREST(b build.Registry, pn kclient.PodsNamespacer, connectionInfo kclient.ConnectionInfoGetter) *REST { return &REST{ BuildRegistry: b, PodGetter: &podGetter{pn}, ConnectionInfo: connectionInfo, Timeout: defaultTimeout, } } var _ = rest.GetterWithOptions(&REST{}) // Get returns a streamer resource with the contents of the build log func (r *REST) Get(ctx kapi.Context, name string, opts runtime.Object) (runtime.Object, error) { buildLogOpts, ok := opts.(*api.BuildLogOptions) if !ok { return nil, errors.NewBadRequest("did not get an expected options.") } build, err := r.BuildRegistry.GetBuild(ctx, name) if err != nil { return nil, errors.NewNotFound("build", name) } switch build.Status { // Build has not launched, wait til it runs case api.BuildStatusNew, api.BuildStatusPending: if buildLogOpts.NoWait {