forked from openshift/ansible-service-broker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit * adding DAO implementation for CRDs * adding CRDs to deploy template * adding CRDs to k8s templates. * working CRD dao implementation. * Implement error checking for IsNotFound error int he dao impl * implement errors returns for conversion methods
- Loading branch information
1 parent
2d57b60
commit 6b5cf4b
Showing
10 changed files
with
1,418 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package clients | ||
|
||
import ( | ||
"errors" | ||
|
||
clientset "github.com/automationbroker/broker-client-go/client/clientset/versioned" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/util/homedir" | ||
) | ||
|
||
// CRD - Client to interact with automationbroker crd API | ||
type CRD struct { | ||
clientset.Interface | ||
} | ||
|
||
// CRDClient - Create a new kubernetes client if needed, returns reference | ||
func CRDClient() (*CRD, error) { | ||
once.CRD.Do(func() { | ||
client, err := newCRDClient() | ||
if err != nil { | ||
log.Error(err.Error()) | ||
panic(err.Error()) | ||
} | ||
instances.CRD = client | ||
}) | ||
if instances.CRD == nil { | ||
return nil, errors.New("CRDClient client instance is nil") | ||
} | ||
return instances.CRD, nil | ||
} | ||
|
||
func newCRDClient() (*CRD, error) { | ||
// NOTE: Both the external and internal client object are using the same | ||
// clientset library. Internal clientset normally uses a different | ||
// library | ||
clientConfig, err := rest.InClusterConfig() | ||
if err != nil { | ||
log.Warning("Failed to create a InternalClientSet: %v.", err) | ||
|
||
log.Debug("Checking for a local Cluster Config") | ||
clientConfig, err = createClientConfigFromFile(homedir.HomeDir() + "/.kube/config") | ||
if err != nil { | ||
log.Error("Failed to create LocalClientSet") | ||
return nil, err | ||
} | ||
} | ||
|
||
clientset, err := clientset.NewForConfig(clientConfig) | ||
if err != nil { | ||
log.Error("Failed to create LocalClientSet") | ||
return nil, err | ||
} | ||
c := &CRD{clientset} | ||
return c, err | ||
} |
Oops, something went wrong.