diff --git a/tools/kubernetes.go b/tools/kubernetes.go index ec5d62c..d1381ba 100644 --- a/tools/kubernetes.go +++ b/tools/kubernetes.go @@ -27,7 +27,11 @@ var gvrSources = schema.GroupVersionResource{Group: "multicluster.admiralty.io", var gvrTargets = schema.GroupVersionResource{Group: "multicluster.admiralty.io", Version: "v1alpha1", Resource: "targets"} type KubernetesService struct { - Set *kubernetes.Clientset + Set *kubernetes.Clientset + Host string + CA string + Cert string + Data string } func NewDynamicClient(host string, ca string, cert string, data string) (*dynamic.DynamicClient, error) { @@ -81,7 +85,11 @@ func NewKubernetesService(host string, ca string, cert string, data string) (*Ku } return &KubernetesService{ - Set: clientset, + Set: clientset, + Host: host, + CA: ca, + Cert: cert, + Data: data, }, nil } @@ -109,7 +117,11 @@ func NewRemoteKubernetesService(url string, ca string, cert string, key string) } return &KubernetesService{ - Set: clientset, + 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()) }