Skip to content

Commit

Permalink
Merge pull request #5865 from abhi-kn/channel-crd
Browse files Browse the repository at this point in the history
added service to fetch knative channel crds
  • Loading branch information
openshift-merge-robot committed Jul 7, 2020
2 parents 31f4ded + d3987a3 commit 9bf0541
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,24 @@ func main() {
knative.EventSourceFilter,
)

srv.KnativeChannelCRDLister = server.NewResourceLister(
resourceListerToken,
&url.URL{
Scheme: k8sEndpoint.Scheme,
Host: k8sEndpoint.Host,
Path: "/apis/apiextensions.k8s.io/v1/customresourcedefinitions",
RawQuery: url.Values{
"labelSelector": {"duck.knative.dev/addressable=true,messaging.knative.dev/subscribable=true"},
}.Encode(),
},
&http.Client{
Transport: &http.Transport{
TLSClientConfig: srv.K8sProxyConfig.TLSClientConfig,
},
},
knative.ChannelFilter,
)

listenURL := bridge.ValidateFlagIsURL("listen", *fListen)
switch listenURL.Scheme {
case "http":
Expand Down
3 changes: 3 additions & 0 deletions pkg/knative/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ type EventSourceList struct {
// items list individual EventSourceDefinition objects
Items []EventSourceDefinition `json:"items" protobuf:"bytes,2,rep,name=items"`
}

// ChannelList is a list of CRD per Channel
type ChannelList = EventSourceList
15 changes: 15 additions & 0 deletions pkg/knative/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ func EventSourceFilter(w http.ResponseWriter, r *http.Response) {
serverutils.SendResponse(w, http.StatusInternalServerError, serverutils.ApiError{Err: err.Error()})
}
}

// ChannelFilter shall filter partial metadata from knative channel CRDs before propagating
func ChannelFilter(w http.ResponseWriter, r *http.Response) {
var channelList ChannelList

if err := json.NewDecoder(r.Body).Decode(&channelList); err != nil {
plog.Errorf("Channel CRD response deserialization failed: %s", err)
serverutils.SendResponse(w, http.StatusInternalServerError, serverutils.ApiError{Err: err.Error()})
}

if err := json.NewEncoder(w).Encode(channelList); err != nil {
plog.Errorf("Channel CRD response serialization failed: %s", err)
serverutils.SendResponse(w, http.StatusInternalServerError, serverutils.ApiError{Err: err.Error()})
}
}
6 changes: 6 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type Server struct {
// A lister for resource listing of a particular kind
MonitoringDashboardConfigMapLister ResourceLister
KnativeEventSourceCRDLister ResourceLister
KnativeChannelCRDLister ResourceLister
HelmChartRepoProxyConfig *proxy.Config
GOARCH string
GOOS string
Expand Down Expand Up @@ -352,6 +353,7 @@ func (s *Server) HTTPHandler() http.Handler {

handle("/api/console/monitoring-dashboard-config", authHandler(s.handleMonitoringDashboardConfigmaps))
handle("/api/console/knative-event-sources", authHandler(s.handleKnativeEventSourceCRDs))
handle("/api/console/knative-channels", authHandler(s.handleKnativeChannelCRDs))
handle("/api/console/version", authHandler(s.versionHandler))

// Helm Endpoints
Expand Down Expand Up @@ -399,6 +401,10 @@ func (s *Server) handleKnativeEventSourceCRDs(w http.ResponseWriter, r *http.Req
s.KnativeEventSourceCRDLister.HandleResources(w, r)
}

func (s *Server) handleKnativeChannelCRDs(w http.ResponseWriter, r *http.Request) {
s.KnativeChannelCRDLister.HandleResources(w, r)
}

func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
jsg := &jsGlobals{
ConsoleVersion: version.Version,
Expand Down

0 comments on commit 9bf0541

Please sign in to comment.