github.com/docker/compose-on-kubernetes@v0.5.0/internal/registry/logs.go (about)

     1  package registry
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"github.com/docker/compose-on-kubernetes/api/compose/latest"
     8  	log "github.com/sirupsen/logrus"
     9  	"k8s.io/apimachinery/pkg/runtime"
    10  	genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
    11  	"k8s.io/apiserver/pkg/registry/rest"
    12  	restclient "k8s.io/client-go/rest"
    13  )
    14  
    15  type stackLogRest struct {
    16  	config *restclient.Config
    17  }
    18  
    19  var _ rest.Storage = &stackLogRest{}
    20  var _ rest.Connecter = &stackLogRest{}
    21  
    22  // NewStackLogRest returns a rest storage for log subresource
    23  func NewStackLogRest(config *restclient.Config) rest.Storage {
    24  	return &stackLogRest{config: config}
    25  }
    26  
    27  func (s *stackLogRest) New() runtime.Object {
    28  	return &latest.Stack{} // Not used here, but needs to be a valid and registered type.
    29  }
    30  
    31  // ProducesMIMETypes returns a list of the MIME types the specified HTTP verb (GET, POST, DELETE,
    32  // PATCH) can respond with.
    33  func (s *stackLogRest) ProducesMIMETypes(verb string) []string {
    34  	return []string{"application/octet-stream"}
    35  }
    36  
    37  // ProducesObject returns an object the specified HTTP verb respond with. It will overwrite storage object if
    38  // it is not nil. Only the type of the return object matters, the value will be ignored.
    39  func (s *stackLogRest) ProducesObject(verb string) interface{} {
    40  	return nil
    41  }
    42  
    43  func (s *stackLogRest) ConnectMethods() []string {
    44  	return []string{"GET"}
    45  }
    46  
    47  func (s *stackLogRest) NewConnectOptions() (runtime.Object, bool, string) {
    48  	return nil, false, ""
    49  }
    50  
    51  func (s *stackLogRest) Connect(ctx context.Context, name string, options runtime.Object, r rest.Responder) (http.Handler, error) {
    52  	namespace, _ := genericapirequest.NamespaceFrom(ctx)
    53  	log.Infof("log connect %s/%s", namespace, name)
    54  	return &logStreamer{s.config, namespace, name}, nil
    55  }