This commit is contained in:
mr
2026-02-24 10:36:10 +01:00
parent 54aef164ba
commit a9ebad78f3

View File

@@ -27,7 +27,11 @@ var gvrSources = schema.GroupVersionResource{Group: "multicluster.admiralty.io",
var gvrTargets = schema.GroupVersionResource{Group: "multicluster.admiralty.io", Version: "v1alpha1", Resource: "targets"} var gvrTargets = schema.GroupVersionResource{Group: "multicluster.admiralty.io", Version: "v1alpha1", Resource: "targets"}
type KubernetesService struct { 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) { 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{ return &KubernetesService{
Set: clientset, Set: clientset,
Host: host,
CA: ca,
Cert: cert,
Data: data,
}, nil }, nil
} }
@@ -109,7 +117,11 @@ func NewRemoteKubernetesService(url string, ca string, cert string, key string)
} }
return &KubernetesService{ return &KubernetesService{
Set: clientset, Set: clientset,
Host: url,
CA: string(decodedCa),
Cert: string(decodedCert),
Data: string(decodedKey),
}, nil }, nil
} }
@@ -205,7 +217,7 @@ func (k *KubernetesService) CreateRoleBinding(ctx context.Context, ns string, ro
return nil 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{ targetGVR := schema.GroupVersionResource{
Group: "multicluster.admiralty.io", Group: "multicluster.admiralty.io",
Version: "v1alpha1", Version: "v1alpha1",
@@ -213,7 +225,7 @@ func (k *KubernetesService) DeleteNamespace(ctx context.Context, host string, ca
} }
// Delete the Target // Delete the Target
dyn, err := NewDynamicClient(host, ca, cert, data) dyn, err := NewDynamicClient(k.Host, k.CA, k.Cert, k.Data)
if err != nil { if err != nil {
return err 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 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 // - 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) exists, err := k.GetKubeconfigSecret(context, executionId, peerId)
if err != nil { if err != nil {
fmt.Println("Error verifying kube-secret before creating target") 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 { if err != nil {
return nil, errors.New("Error when trying to apply Target definition :" + err.Error()) 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 // 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 // to rather contact the oc-datacenter from the remote cluster to create the source
// locally and retrieve the token for the serviceAccount // 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{}{ source := map[string]interface{}{
"apiVersion": "multicluster.admiralty.io/v1alpha1", "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 { if err != nil {
return nil, errors.New("Error when trying to apply Source definition :" + err.Error()) return nil, errors.New("Error when trying to apply Source definition :" + err.Error())
} }