diff --git a/internal/btp/operator/gvk.go b/internal/btp/operator/gvk.go deleted file mode 100644 index e09ae867f..000000000 --- a/internal/btp/operator/gvk.go +++ /dev/null @@ -1,16 +0,0 @@ -package operator - -import "k8s.io/apimachinery/pkg/runtime/schema" - -var ( - GVKServiceInstance = schema.GroupVersionKind{ - Group: "services.cloud.sap.com", - Version: "v1", - Kind: "ServiceInstance", - } - GVKServiceBinding = schema.GroupVersionKind{ - Group: "services.cloud.sap.com", - Version: "v1", - Kind: "ServiceBinding", - } -) diff --git a/internal/btp/operator/gvr.go b/internal/btp/operator/gvr.go deleted file mode 100644 index 844b61ea2..000000000 --- a/internal/btp/operator/gvr.go +++ /dev/null @@ -1,16 +0,0 @@ -package operator - -import "k8s.io/apimachinery/pkg/runtime/schema" - -var ( - GVRServiceInstance = schema.GroupVersionResource{ - Group: "services.cloud.sap.com", - Version: "v1", - Resource: "serviceinstances", - } - GVRServiceBinding = schema.GroupVersionResource{ - Group: "services.cloud.sap.com", - Version: "v1", - Resource: "servicebindings", - } -) diff --git a/internal/cmd/alpha/add/managed/managed.go b/internal/cmd/alpha/add/managed/managed.go index 1cf061f88..7eb64e2ad 100644 --- a/internal/cmd/alpha/add/managed/managed.go +++ b/internal/cmd/alpha/add/managed/managed.go @@ -3,7 +3,7 @@ package managed import ( "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" - "github.com/kyma-project/cli.v3/internal/kyma" + "github.com/kyma-project/cli.v3/internal/kube/kyma" "github.com/spf13/cobra" ) diff --git a/internal/cmd/alpha/add/managed/managed_test.go b/internal/cmd/alpha/add/managed/managed_test.go index 13300f2e3..d2ecd62f1 100644 --- a/internal/cmd/alpha/add/managed/managed_test.go +++ b/internal/cmd/alpha/add/managed/managed_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/kyma-project/cli.v3/internal/kyma" + "github.com/kyma-project/cli.v3/internal/kube/kyma" "github.com/stretchr/testify/require" ) diff --git a/internal/cmd/alpha/hana/check.go b/internal/cmd/alpha/hana/check.go index 8bc6a8932..09db8cc21 100644 --- a/internal/cmd/alpha/hana/check.go +++ b/internal/cmd/alpha/hana/check.go @@ -7,7 +7,7 @@ import ( "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" - "github.com/kyma-project/cli.v3/internal/kube" + "github.com/kyma-project/cli.v3/internal/kube/btp" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -72,18 +72,18 @@ func runCheck(config *hanaCheckConfig) clierror.Error { } func checkHanaInstance(config *hanaCheckConfig) clierror.Error { - u, err := kube.GetServiceInstance(config.KubeClient, config.Ctx, config.namespace, config.name) + u, err := btp.GetServiceInstance(config.KubeClient, config.Ctx, config.namespace, config.name) return handleCheckResponse(u, err, "Hana instance", config.namespace, config.name) } func checkHanaBinding(config *hanaCheckConfig) clierror.Error { - u, err := kube.GetServiceBinding(config.KubeClient, config.Ctx, config.namespace, config.name) + u, err := btp.GetServiceBinding(config.KubeClient, config.Ctx, config.namespace, config.name) return handleCheckResponse(u, err, "Hana binding", config.namespace, config.name) } func checkHanaBindingURL(config *hanaCheckConfig) clierror.Error { urlName := hanaBindingURLName(config.name) - u, err := kube.GetServiceBinding(config.KubeClient, config.Ctx, config.namespace, urlName) + u, err := btp.GetServiceBinding(config.KubeClient, config.Ctx, config.namespace, urlName) return handleCheckResponse(u, err, "Hana URL binding", config.namespace, urlName) } @@ -94,7 +94,7 @@ func handleCheckResponse(u *unstructured.Unstructured, err error, printedName, n ) } - ready, error := kube.IsReady(u) + ready, error := btp.IsReady(u) if error != nil { return clierror.Wrap(err, clierror.New("failed to check readiness of Hana resources"), diff --git a/internal/cmd/alpha/hana/check_test.go b/internal/cmd/alpha/hana/check_test.go index 8f8fc5ac0..1e620ccf0 100644 --- a/internal/cmd/alpha/hana/check_test.go +++ b/internal/cmd/alpha/hana/check_test.go @@ -2,15 +2,16 @@ package hana import ( "context" - "github.com/kyma-project/cli.v3/internal/btp/operator" + "testing" + "github.com/kyma-project/cli.v3/internal/cmdcommon" + "github.com/kyma-project/cli.v3/internal/kube/btp" kube_fake "github.com/kyma-project/cli.v3/internal/kube/fake" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" dynamic_fake "k8s.io/client-go/dynamic/fake" - "testing" ) func Test_checkHanaInstance(t *testing.T) { @@ -122,7 +123,7 @@ func Test_checkHanaBindingURL(t *testing.T) { func fixCheckConfig(name string, namespace string, objects ...runtime.Object) hanaCheckConfig { scheme := runtime.NewScheme() - scheme.AddKnownTypes(operator.GVRServiceInstance.GroupVersion()) + scheme.AddKnownTypes(btp.GVRServiceInstance.GroupVersion()) dynamic := dynamic_fake.NewSimpleDynamicClient(scheme, objects...) config := hanaCheckConfig{ KymaConfig: &cmdcommon.KymaConfig{Ctx: context.Background()}, diff --git a/internal/cmd/alpha/hana/delete.go b/internal/cmd/alpha/hana/delete.go index c378f684c..4ddcd0a0b 100644 --- a/internal/cmd/alpha/hana/delete.go +++ b/internal/cmd/alpha/hana/delete.go @@ -3,9 +3,9 @@ package hana import ( "fmt" - "github.com/kyma-project/cli.v3/internal/btp/operator" "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" + "github.com/kyma-project/cli.v3/internal/kube/btp" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -69,14 +69,14 @@ func runDelete(config *hanaDeleteConfig) clierror.Error { } func deleteHanaInstance(config *hanaDeleteConfig) clierror.Error { - err := config.KubeClient.Dynamic().Resource(operator.GVRServiceInstance). + err := config.KubeClient.Dynamic().Resource(btp.GVRServiceInstance). Namespace(config.namespace). Delete(config.Ctx, config.name, metav1.DeleteOptions{}) return handleDeleteResponse(err, "Hana instance", config.namespace, config.name) } func deleteHanaBinding(config *hanaDeleteConfig) clierror.Error { - err := config.KubeClient.Dynamic().Resource(operator.GVRServiceBinding). + err := config.KubeClient.Dynamic().Resource(btp.GVRServiceBinding). Namespace(config.namespace). Delete(config.Ctx, config.name, metav1.DeleteOptions{}) return handleDeleteResponse(err, "Hana binding", config.namespace, config.name) @@ -84,7 +84,7 @@ func deleteHanaBinding(config *hanaDeleteConfig) clierror.Error { func deleteHanaBindingURL(config *hanaDeleteConfig) clierror.Error { urlName := hanaBindingURLName(config.name) - err := config.KubeClient.Dynamic().Resource(operator.GVRServiceBinding). + err := config.KubeClient.Dynamic().Resource(btp.GVRServiceBinding). Namespace(config.namespace). Delete(config.Ctx, urlName, metav1.DeleteOptions{}) return handleDeleteResponse(err, "Hana URL binding", config.namespace, urlName) diff --git a/internal/cmd/alpha/hana/map.go b/internal/cmd/alpha/hana/map.go index 4268c8b9b..8c1d1cd89 100644 --- a/internal/cmd/alpha/hana/map.go +++ b/internal/cmd/alpha/hana/map.go @@ -8,10 +8,10 @@ import ( "time" "github.com/kyma-project/cli.v3/internal/btp/auth" - "github.com/kyma-project/cli.v3/internal/btp/operator" "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" "github.com/kyma-project/cli.v3/internal/kube" + "github.com/kyma-project/cli.v3/internal/kube/btp" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -71,7 +71,7 @@ func runMap(config *hanaCheckConfig) clierror.Error { func createHanaAPIInstanceIfNeeded(config *hanaCheckConfig) clierror.Error { // check if instance exists, skip API instance creation if it does - instance, err := kube.GetServiceInstance(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) + instance, err := btp.GetServiceInstance(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) if err == nil && instance != nil { fmt.Printf("Hana API instance already exists (%s/%s)\n", config.namespace, hanaBindingAPIName(config.name)) return nil @@ -81,7 +81,7 @@ func createHanaAPIInstanceIfNeeded(config *hanaCheckConfig) clierror.Error { func createHanaAPIBindingIfNeeded(config *hanaCheckConfig) clierror.Error { //check if binding exists, skip API binding creation if it does - instance, err := kube.GetServiceBinding(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) + instance, err := btp.GetServiceBinding(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) if err == nil && instance != nil { fmt.Printf("Hana API instance already exists (%s/%s)\n", config.namespace, hanaBindingAPIName(config.name)) return nil @@ -97,7 +97,7 @@ func createHanaAPIInstance(config *hanaCheckConfig) clierror.Error { return clierror.Wrap(err, clierror.New("failed to create Hana API instance object")) } - _, err = config.KubeClient.Dynamic().Resource(operator.GVRServiceInstance). + _, err = config.KubeClient.Dynamic().Resource(btp.GVRServiceInstance). Namespace(config.namespace). Create(config.Ctx, data, metav1.CreateOptions{}) return handleProvisionResponse(err, "Hana API instance", config.namespace, hanaBindingAPIName(config.name)) @@ -108,17 +108,17 @@ func createHanaAPIBinding(config *hanaCheckConfig) clierror.Error { if err != nil { return clierror.Wrap(err, clierror.New("failed to create Hana API binding object")) } - _, err = config.KubeClient.Dynamic().Resource(operator.GVRServiceBinding). + _, err = config.KubeClient.Dynamic().Resource(btp.GVRServiceBinding). Namespace(config.namespace). Create(config.Ctx, data, metav1.CreateOptions{}) return handleProvisionResponse(err, "Hana API binding", config.namespace, hanaBindingAPIName(config.name)) } func hanaAPIInstance(config *hanaCheckConfig) (*unstructured.Unstructured, error) { - requestData := kube.ServiceInstance{ + requestData := btp.ServiceInstance{ TypeMeta: metav1.TypeMeta{ - APIVersion: kube.ServicesAPIVersionV1, - Kind: kube.KindServiceInstance, + APIVersion: btp.ServicesAPIVersionV1, + Kind: btp.KindServiceInstance, }, ObjectMeta: metav1.ObjectMeta{ Name: hanaBindingAPIName(config.name), @@ -127,7 +127,7 @@ func hanaAPIInstance(config *hanaCheckConfig) (*unstructured.Unstructured, error "app.kubernetes.io/name": hanaBindingAPIName(config.name), }, }, - Spec: kube.ServiceInstanceSpec{ + Spec: btp.ServiceInstanceSpec{ Parameters: HanaAPIParameters{ TechnicalUser: true, }, @@ -135,15 +135,15 @@ func hanaAPIInstance(config *hanaCheckConfig) (*unstructured.Unstructured, error PlanName: "admin-api-access", }, } - return kube.ToUnstructured(requestData, operator.GVKServiceInstance) + return kube.ToUnstructured(requestData, btp.GVKServiceInstance) } func hanaAPIBinding(config *hanaCheckConfig) (*unstructured.Unstructured, error) { instanceName := hanaBindingAPIName(config.name) - requestData := kube.ServiceBinding{ + requestData := btp.ServiceBinding{ TypeMeta: metav1.TypeMeta{ - APIVersion: kube.ServicesAPIVersionV1, - Kind: kube.KindServiceBinding, + APIVersion: btp.ServicesAPIVersionV1, + Kind: btp.KindServiceBinding, }, ObjectMeta: metav1.ObjectMeta{ Name: instanceName, @@ -152,12 +152,12 @@ func hanaAPIBinding(config *hanaCheckConfig) (*unstructured.Unstructured, error) "app.kubernetes.io/name": hanaBindingAPIName(config.name), }, }, - Spec: kube.ServiceBindingSpec{ + Spec: btp.ServiceBindingSpec{ ServiceInstanceName: instanceName, SecretName: instanceName, }, } - return kube.ToUnstructured(requestData, operator.GVKServiceBinding) + return kube.ToUnstructured(requestData, btp.GVKServiceBinding) } func hanaBindingAPIName(name string) string { @@ -201,7 +201,7 @@ func getClusterID(config *hanaCheckConfig) (string, clierror.Error) { func getHanaID(config *hanaCheckConfig) (string, clierror.Error) { // wait for until Hana instance is ready, for default setting it should take 5 minutes fmt.Print("waiting for Hana instance to be ready... ") - instanceReadyCheck := kube.IsInstanceReady(config.KubeClient, config.Ctx, config.namespace, config.name) + instanceReadyCheck := btp.IsInstanceReady(config.KubeClient, config.Ctx, config.namespace, config.name) err := wait.PollUntilContextTimeout(config.Ctx, 10*time.Second, config.timeout, true, instanceReadyCheck) if err != nil { fmt.Println("Failed") @@ -211,13 +211,13 @@ func getHanaID(config *hanaCheckConfig) (string, clierror.Error) { } fmt.Println("done") - u, err := config.KubeClient.Dynamic().Resource(operator.GVRServiceInstance). + u, err := config.KubeClient.Dynamic().Resource(btp.GVRServiceInstance). Namespace(config.namespace). Get(config.Ctx, config.name, metav1.GetOptions{}) if err != nil { return "", clierror.Wrap(err, clierror.New("failed to get Hana instance")) } - status, err := kube.GetServiceStatus(u) + status, err := btp.GetServiceStatus(u) if err != nil { return "", clierror.Wrap(err, clierror.New("failed to read resource data")) } @@ -227,7 +227,7 @@ func getHanaID(config *hanaCheckConfig) (string, clierror.Error) { func readHanaAPISecret(config *hanaCheckConfig) (string, *auth.UAA, clierror.Error) { fmt.Print("waiting for Hana API instance to be ready... ") - instanceReadyCheck := kube.IsInstanceReady(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) + instanceReadyCheck := btp.IsInstanceReady(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) err := wait.PollUntilContextTimeout(config.Ctx, 5*time.Second, 2*time.Minute, true, instanceReadyCheck) if err != nil { fmt.Println("Failed") @@ -238,7 +238,7 @@ func readHanaAPISecret(config *hanaCheckConfig) (string, *auth.UAA, clierror.Err fmt.Println("done") fmt.Print("waiting for Hana API binding to be ready... ") - bindingReadyCheck := kube.IsBindingReady(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) + bindingReadyCheck := btp.IsBindingReady(config.KubeClient, config.Ctx, config.namespace, hanaBindingAPIName(config.name)) err = wait.PollUntilContextTimeout(config.Ctx, 5*time.Second, 2*time.Minute, true, bindingReadyCheck) if err != nil { fmt.Println("Failed") diff --git a/internal/cmd/alpha/hana/provision.go b/internal/cmd/alpha/hana/provision.go index 903a78b2e..80767f4cf 100644 --- a/internal/cmd/alpha/hana/provision.go +++ b/internal/cmd/alpha/hana/provision.go @@ -3,9 +3,9 @@ package hana import ( "fmt" - "github.com/kyma-project/cli.v3/internal/btp/operator" "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" + "github.com/kyma-project/cli.v3/internal/kube/btp" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -78,21 +78,21 @@ func runProvision(config *hanaProvisionConfig) clierror.Error { } func createHanaInstance(config *hanaProvisionConfig) clierror.Error { - _, err := config.KubeClient.Dynamic().Resource(operator.GVRServiceInstance). + _, err := config.KubeClient.Dynamic().Resource(btp.GVRServiceInstance). Namespace(config.namespace). Create(config.Ctx, hanaInstance(config), metav1.CreateOptions{}) return handleProvisionResponse(err, "Hana instance", config.namespace, config.name) } func createHanaBinding(config *hanaProvisionConfig) clierror.Error { - _, err := config.KubeClient.Dynamic().Resource(operator.GVRServiceBinding). + _, err := config.KubeClient.Dynamic().Resource(btp.GVRServiceBinding). Namespace(config.namespace). Create(config.Ctx, hanaBinding(config), metav1.CreateOptions{}) return handleProvisionResponse(err, "Hana binding", config.namespace, config.name) } func createHanaBindingURL(config *hanaProvisionConfig) clierror.Error { - _, err := config.KubeClient.Dynamic().Resource(operator.GVRServiceBinding). + _, err := config.KubeClient.Dynamic().Resource(btp.GVRServiceBinding). Namespace(config.namespace). Create(config.Ctx, hanaBindingURL(config), metav1.CreateOptions{}) return handleProvisionResponse(err, "Hana URL binding", config.namespace, hanaBindingURLName(config.name)) diff --git a/internal/cmd/alpha/referenceinstance/referenceinstance.go b/internal/cmd/alpha/referenceinstance/referenceinstance.go index cfe9cc3b6..cf14168d1 100644 --- a/internal/cmd/alpha/referenceinstance/referenceinstance.go +++ b/internal/cmd/alpha/referenceinstance/referenceinstance.go @@ -1,10 +1,10 @@ package referenceinstance import ( - "github.com/kyma-project/cli.v3/internal/btp/operator" "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" "github.com/kyma-project/cli.v3/internal/kube" + "github.com/kyma-project/cli.v3/internal/kube/btp" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -67,17 +67,17 @@ func NewReferenceInstanceCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command { func runReferenceInstance(config referenceInstanceConfig) error { requestData := fillRequestData(config) - unstructuredObj, err := kube.ToUnstructured(requestData, operator.GVKServiceInstance) + unstructuredObj, err := kube.ToUnstructured(requestData, btp.GVKServiceInstance) if err != nil { return err } - _, err = config.KubeClient.Dynamic().Resource(operator.GVRServiceInstance).Namespace(config.namespace).Create(config.Ctx, unstructuredObj, metav1.CreateOptions{}) + _, err = config.KubeClient.Dynamic().Resource(btp.GVRServiceInstance).Namespace(config.namespace).Create(config.Ctx, unstructuredObj, metav1.CreateOptions{}) return err } -func fillRequestData(config referenceInstanceConfig) kube.ServiceInstance { - requestData := kube.ServiceInstance{ +func fillRequestData(config referenceInstanceConfig) btp.ServiceInstance { + requestData := btp.ServiceInstance{ TypeMeta: metav1.TypeMeta{ APIVersion: "services.cloud.sap.com/v1", Kind: "ServiceInstance", @@ -89,7 +89,7 @@ func fillRequestData(config referenceInstanceConfig) kube.ServiceInstance { "app.kubernetes.io/name": config.referenceName, }, }, - Spec: kube.ServiceInstanceSpec{ + Spec: btp.ServiceInstanceSpec{ Parameters: KubernetesResourceSpecParameters{ InstanceID: config.instanceID, Selectors: SpecSelectors{ diff --git a/internal/cmd/alpha/remove/managed/managed.go b/internal/cmd/alpha/remove/managed/managed.go index 2ca158072..411ccd554 100644 --- a/internal/cmd/alpha/remove/managed/managed.go +++ b/internal/cmd/alpha/remove/managed/managed.go @@ -5,7 +5,7 @@ import ( "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" - "github.com/kyma-project/cli.v3/internal/kyma" + "github.com/kyma-project/cli.v3/internal/kube/kyma" "github.com/spf13/cobra" ) diff --git a/internal/cmd/alpha/remove/managed/managed_test.go b/internal/cmd/alpha/remove/managed/managed_test.go index ed36b6c02..d49ddd57e 100644 --- a/internal/cmd/alpha/remove/managed/managed_test.go +++ b/internal/cmd/alpha/remove/managed/managed_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/kyma-project/cli.v3/internal/kyma" + "github.com/kyma-project/cli.v3/internal/kube/kyma" "github.com/stretchr/testify/require" ) diff --git a/internal/communitymodules/modules.go b/internal/communitymodules/modules.go index 63fc5612c..5493be0fd 100644 --- a/internal/communitymodules/modules.go +++ b/internal/communitymodules/modules.go @@ -10,7 +10,7 @@ import ( "github.com/kyma-project/cli.v3/internal/clierror" "github.com/kyma-project/cli.v3/internal/cmdcommon" - "github.com/kyma-project/cli.v3/internal/kyma" + "github.com/kyma-project/cli.v3/internal/kube/kyma" "golang.org/x/mod/semver" v1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/errors" diff --git a/internal/kube/service.go b/internal/kube/btp/service.go similarity index 80% rename from internal/kube/service.go rename to internal/kube/btp/service.go index 3c62a436d..5a3af24ba 100644 --- a/internal/kube/service.go +++ b/internal/kube/btp/service.go @@ -1,10 +1,10 @@ -package kube +package btp import ( "context" "errors" - "github.com/kyma-project/cli.v3/internal/btp/operator" + "github.com/kyma-project/cli.v3/internal/kube" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -61,14 +61,14 @@ func isConditionTrue(conditions []metav1.Condition, conditionType string) bool { return condition != nil && condition.Status == metav1.ConditionTrue } -func GetServiceInstance(kubeClient Client, ctx context.Context, namespace, name string) (*unstructured.Unstructured, error) { - return kubeClient.Dynamic().Resource(operator.GVRServiceInstance). +func GetServiceInstance(kubeClient kube.Client, ctx context.Context, namespace, name string) (*unstructured.Unstructured, error) { + return kubeClient.Dynamic().Resource(GVRServiceInstance). Namespace(namespace). Get(ctx, name, metav1.GetOptions{}) } -func GetServiceBinding(kubeClient Client, ctx context.Context, namespace, name string) (*unstructured.Unstructured, error) { - return kubeClient.Dynamic().Resource(operator.GVRServiceBinding). +func GetServiceBinding(kubeClient kube.Client, ctx context.Context, namespace, name string) (*unstructured.Unstructured, error) { + return kubeClient.Dynamic().Resource(GVRServiceBinding). Namespace(namespace). Get(ctx, name, metav1.GetOptions{}) } @@ -103,7 +103,7 @@ func isResourceReady(instance *unstructured.Unstructured) (bool, error) { return ready, nil } -func IsBindingReady(kubeClient Client, ctx context.Context, namespace, name string) wait.ConditionWithContextFunc { +func IsBindingReady(kubeClient kube.Client, ctx context.Context, namespace, name string) wait.ConditionWithContextFunc { return func(_ context.Context) (bool, error) { instance, err := GetServiceBinding(kubeClient, ctx, namespace, name) if err != nil { @@ -113,7 +113,7 @@ func IsBindingReady(kubeClient Client, ctx context.Context, namespace, name stri } } -func IsInstanceReady(kubeClient Client, ctx context.Context, namespace, name string) wait.ConditionWithContextFunc { +func IsInstanceReady(kubeClient kube.Client, ctx context.Context, namespace, name string) wait.ConditionWithContextFunc { return func(_ context.Context) (bool, error) { instance, err := GetServiceInstance(kubeClient, ctx, namespace, name) if err != nil { diff --git a/internal/kube/btp/types.go b/internal/kube/btp/types.go new file mode 100644 index 000000000..83aaf8067 --- /dev/null +++ b/internal/kube/btp/types.go @@ -0,0 +1,64 @@ +package btp + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + GVKServiceInstance = schema.GroupVersionKind{ + Group: "services.cloud.sap.com", + Version: "v1", + Kind: "ServiceInstance", + } + GVKServiceBinding = schema.GroupVersionKind{ + Group: "services.cloud.sap.com", + Version: "v1", + Kind: "ServiceBinding", + } +) + +var ( + GVRServiceInstance = schema.GroupVersionResource{ + Group: "services.cloud.sap.com", + Version: "v1", + Resource: "serviceinstances", + } + GVRServiceBinding = schema.GroupVersionResource{ + Group: "services.cloud.sap.com", + Version: "v1", + Resource: "servicebindings", + } +) + +const ( + ServicesAPIVersionV1 = "services.cloud.sap.com/v1" + KindServiceInstance = "ServiceInstance" + KindServiceBinding = "ServiceBinding" +) + +type ServiceInstance struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec ServiceInstanceSpec `json:"spec,omitempty"` +} + +type ServiceBinding struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec ServiceBindingSpec `json:"spec,omitempty"` +} + +type ServiceInstanceSpec struct { + Parameters interface{} `json:"parameters,omitempty"` + OfferingName string `json:"serviceOfferingName,omitempty"` + PlanName string `json:"servicePlanName,omitempty"` + BTPCredentialsSecret string `json:"btpAccessCredentialsSecret,omitempty"` +} + +type ServiceBindingSpec struct { + Parameters interface{} `json:"parameters,omitempty"` + ServiceInstanceName string `json:"serviceInstanceName,omitempty"` + ExternalName string `json:"externalName,omitempty"` + SecretName string `json:"secretName,omitempty"` +} diff --git a/internal/kyma/kyma.go b/internal/kube/kyma/kyma.go similarity index 100% rename from internal/kyma/kyma.go rename to internal/kube/kyma/kyma.go diff --git a/internal/kyma/kyma_test.go b/internal/kube/kyma/kyma_test.go similarity index 100% rename from internal/kyma/kyma_test.go rename to internal/kube/kyma/kyma_test.go diff --git a/internal/kyma/types.go b/internal/kube/kyma/types.go similarity index 100% rename from internal/kyma/types.go rename to internal/kube/kyma/types.go diff --git a/internal/kube/unstructured.go b/internal/kube/unstructured.go index 2a381c97b..007a8ea45 100644 --- a/internal/kube/unstructured.go +++ b/internal/kube/unstructured.go @@ -1,44 +1,11 @@ package kube import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" ) -const ( - ServicesAPIVersionV1 = "services.cloud.sap.com/v1" - KindServiceInstance = "ServiceInstance" - KindServiceBinding = "ServiceBinding" -) - -type ServiceInstance struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ServiceInstanceSpec `json:"spec,omitempty"` -} - -type ServiceBinding struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ServiceBindingSpec `json:"spec,omitempty"` -} - -type ServiceInstanceSpec struct { - Parameters interface{} `json:"parameters,omitempty"` - OfferingName string `json:"serviceOfferingName,omitempty"` - PlanName string `json:"servicePlanName,omitempty"` - BTPCredentialsSecret string `json:"btpAccessCredentialsSecret,omitempty"` -} - -type ServiceBindingSpec struct { - Parameters interface{} `json:"parameters,omitempty"` - ServiceInstanceName string `json:"serviceInstanceName,omitempty"` - ExternalName string `json:"externalName,omitempty"` - SecretName string `json:"secretName,omitempty"` -} - // ToUnstructured converts the given data to an Unstructured object func ToUnstructured(requestData interface{}, gvk schema.GroupVersionKind) (*unstructured.Unstructured, error) { u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&requestData)