kube
This commit is contained in:
@@ -28,6 +28,10 @@ var gvrTargets = schema.GroupVersionResource{Group: "multicluster.admiralty.io",
|
||||
|
||||
type KubernetesService struct {
|
||||
Set *kubernetes.Clientset
|
||||
Host string
|
||||
CA string
|
||||
Cert string
|
||||
Data string
|
||||
}
|
||||
|
||||
func NewDynamicClient(host string, ca string, cert string, data string) (*dynamic.DynamicClient, error) {
|
||||
@@ -82,6 +86,10 @@ func NewKubernetesService(host string, ca string, cert string, data string) (*Ku
|
||||
|
||||
return &KubernetesService{
|
||||
Set: clientset,
|
||||
Host: host,
|
||||
CA: ca,
|
||||
Cert: cert,
|
||||
Data: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -110,6 +118,10 @@ func NewRemoteKubernetesService(url string, ca string, cert string, key string)
|
||||
|
||||
return &KubernetesService{
|
||||
Set: clientset,
|
||||
Host: url,
|
||||
CA: string(decodedCa),
|
||||
Cert: string(decodedCert),
|
||||
Data: string(decodedKey),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -205,7 +217,7 @@ func (k *KubernetesService) CreateRoleBinding(ctx context.Context, ns string, ro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *KubernetesService) DeleteNamespace(ctx context.Context, host string, ca string, cert string, data string, ns string, f func()) error {
|
||||
func (k *KubernetesService) DeleteNamespace(ctx context.Context, ns string, f func()) error {
|
||||
targetGVR := schema.GroupVersionResource{
|
||||
Group: "multicluster.admiralty.io",
|
||||
Version: "v1alpha1",
|
||||
@@ -213,7 +225,7 @@ func (k *KubernetesService) DeleteNamespace(ctx context.Context, host string, ca
|
||||
}
|
||||
|
||||
// Delete the Target
|
||||
dyn, err := NewDynamicClient(host, ca, cert, data)
|
||||
dyn, err := NewDynamicClient(k.Host, k.CA, k.Cert, k.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -311,7 +323,7 @@ func (k *KubernetesService) GetTargets(ctx context.Context) ([]string, error) {
|
||||
// - have declared the same namespace as the one where the pods are created in the local cluster
|
||||
//
|
||||
// - have delcared a serviceAccount with sufficient permission to create pods
|
||||
func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, host string, ca string, cert string, data string, executionId string, peerId string) ([]byte, error) {
|
||||
func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, executionId string, peerId string) ([]byte, error) {
|
||||
exists, err := k.GetKubeconfigSecret(context, executionId, peerId)
|
||||
if err != nil {
|
||||
fmt.Println("Error verifying kube-secret before creating target")
|
||||
@@ -341,7 +353,7 @@ func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, host
|
||||
},
|
||||
}
|
||||
|
||||
res, err := dynamicClientApply(host, ca, cert, data, executionId, targetName, gvrTargets, context, target)
|
||||
res, err := dynamicClientApply(k.Host, k.CA, k.Cert, k.Data, executionId, targetName, gvrTargets, context, target)
|
||||
if err != nil {
|
||||
return nil, errors.New("Error when trying to apply Target definition :" + err.Error())
|
||||
}
|
||||
@@ -358,7 +370,7 @@ func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, host
|
||||
// This method is temporary to implement the use of Admiralty, but must be edited
|
||||
// to rather contact the oc-datacenter from the remote cluster to create the source
|
||||
// locally and retrieve the token for the serviceAccount
|
||||
func (k *KubernetesService) CreateAdmiraltySource(context context.Context, host string, ca string, cert string, data string, executionId string) ([]byte, error) {
|
||||
func (k *KubernetesService) CreateAdmiraltySource(context context.Context, executionId string) ([]byte, error) {
|
||||
|
||||
source := map[string]interface{}{
|
||||
"apiVersion": "multicluster.admiralty.io/v1alpha1",
|
||||
@@ -372,7 +384,7 @@ func (k *KubernetesService) CreateAdmiraltySource(context context.Context, host
|
||||
},
|
||||
}
|
||||
|
||||
res, err := dynamicClientApply(host, ca, cert, data, executionId, "source-"+executionId, gvrSources, context, source)
|
||||
res, err := dynamicClientApply(k.Host, k.CA, k.Cert, k.Data, executionId, "source-"+executionId, gvrSources, context, source)
|
||||
if err != nil {
|
||||
return nil, errors.New("Error when trying to apply Source definition :" + err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user