-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kie-issues-314: Operator driven service discovery API Phase3
- Code review suggestions 1
- Loading branch information
Showing
19 changed files
with
392 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package knative | ||
|
||
import ( | ||
"k8s.io/client-go/discovery" | ||
"k8s.io/client-go/rest" | ||
clienteventingv1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1" | ||
clientservingv1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1" | ||
) | ||
|
||
var servingClient clientservingv1.ServingV1Interface | ||
var eventingClient clienteventingv1.EventingV1Interface | ||
|
||
type Info struct { | ||
IsKnativeEventing bool | ||
IsKnativeServing bool | ||
} | ||
|
||
func GetKnativeServingClient(cfg *rest.Config) (clientservingv1.ServingV1Interface, error) { | ||
if servingClient == nil { | ||
if knServingClient, err := NewKnativeServingClient(cfg); err != nil { | ||
return nil, err | ||
} else { | ||
servingClient = knServingClient | ||
} | ||
} | ||
return servingClient, nil | ||
} | ||
|
||
func GetKnativeEventingClient(cfg *rest.Config) (clienteventingv1.EventingV1Interface, error) { | ||
if eventingClient == nil { | ||
if knEventingClient, err := NewKnativeEventingClient(cfg); err != nil { | ||
return nil, err | ||
} else { | ||
eventingClient = knEventingClient | ||
} | ||
} | ||
return eventingClient, nil | ||
} | ||
|
||
func NewKnativeServingClient(cfg *rest.Config) (*clientservingv1.ServingV1Client, error) { | ||
return clientservingv1.NewForConfig(cfg) | ||
} | ||
|
||
func NewKnativeEventingClient(cfg *rest.Config) (*clienteventingv1.EventingV1Client, error) { | ||
return clienteventingv1.NewForConfig(cfg) | ||
} | ||
|
||
func GetKnativeInfo(cfg *rest.Config) (*Info, error) { | ||
if cli, err := discovery.NewDiscoveryClientForConfig(cfg); err != nil { | ||
return nil, err | ||
} else { | ||
apiList, err := cli.ServerGroups() | ||
if err != nil { | ||
return nil, err | ||
} | ||
result := new(Info) | ||
for _, group := range apiList.Groups { | ||
if group.Name == "serving.knative.dev" { | ||
result.IsKnativeServing = true | ||
} | ||
if group.Name == "eventing.knative.dev" { | ||
result.IsKnativeEventing = true | ||
} | ||
} | ||
return result, nil | ||
} | ||
} |
Oops, something went wrong.