Skip to content

Commit

Permalink
Move all operations on the Kubernetes resources under the kube pkg (k…
Browse files Browse the repository at this point in the history
  • Loading branch information
pPrecel authored Jul 12, 2024
1 parent 0271dcc commit db58aaf
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 120 deletions.
16 changes: 0 additions & 16 deletions internal/btp/operator/gvk.go

This file was deleted.

16 changes: 0 additions & 16 deletions internal/btp/operator/gvr.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/cmd/alpha/add/managed/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/alpha/add/managed/managed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/alpha/hana/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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"),
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/alpha/hana/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()},
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/alpha/hana/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -69,22 +69,22 @@ 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)
}

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)
Expand Down
40 changes: 20 additions & 20 deletions internal/cmd/alpha/hana/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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),
Expand All @@ -127,23 +127,23 @@ func hanaAPIInstance(config *hanaCheckConfig) (*unstructured.Unstructured, error
"app.kubernetes.io/name": hanaBindingAPIName(config.name),
},
},
Spec: kube.ServiceInstanceSpec{
Spec: btp.ServiceInstanceSpec{
Parameters: HanaAPIParameters{
TechnicalUser: true,
},
OfferingName: "hana-cloud",
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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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"))
}
Expand All @@ -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")
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/alpha/hana/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/alpha/referenceinstance/referenceinstance.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/alpha/remove/managed/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Loading

0 comments on commit db58aaf

Please sign in to comment.