diff --git a/.github/workflows/commands.yaml b/.github/workflows/commands.yaml index 272ff58..9a9d33a 100644 --- a/.github/workflows/commands.yaml +++ b/.github/workflows/commands.yaml @@ -10,7 +10,7 @@ on: jobs: install: - name: Run kuadrantctl install + name: Run kuadrantctl generate runs-on: ubuntu-latest env: KIND_CLUSTER_NAME: kuadrantctl-local @@ -22,22 +22,9 @@ jobs: id: go - name: Check out code uses: actions/checkout@v3 - - name: Create k8s Kind Cluster - uses: helm/kind-action@v1.8.0 - with: - version: v0.20.0 - config: utils/kind-cluster.yaml - cluster_name: ${{ env.KIND_CLUSTER_NAME }} - wait: 120s - - name: Check cluster info - run: | - kubectl cluster-info dump - - name: Run make env-setup - run: | - make env-setup - name: build run: | make install - name: run command run: | - bin/kuadrantctl install + bin/kuadrantctl generate gatewayapi httproute --oas examples/oas3/gateway-api-petstore.yaml diff --git a/README.md b/README.md index 77080d3..db0b9b6 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,6 @@ kuadrantctl [command] [subcommand] [flags] | `completion` | Generate autocompletion scripts for the specified shell | | `generate` | Commands related to Kubernetes Gateway API and Kuadrant resource generation from OpenAPI 3.x specifications | | `help` | Help about any command | -| `install` | Install the Kuadrant Operator with OLM to your Kuberenetes or OpenShift cluster | -| `uninstall` | Uninstall Kuadrant Operator from a Kubernetes or OpenShift cluster | | `version` | Print the version number of `kuadrantctl` | ### Flags @@ -92,24 +90,6 @@ Generate Kuadrant resources from an OpenAPI 3.x specification | `ratelimitpolicy`| Generate [Kuadrant RateLimitPolicy](https://docs.kuadrant.io/kuadrant-operator/doc/rate-limiting/) from an OpenAPI 3.0.x specification | `--oas string` Path to OpenAPI spec file (in JSON or YAML format), URL, or '-' to read from standard input (required). `-o` Output format: 'yaml' or 'json'. Default: yaml | -#### `install` - -Install the [Kuadrant Operator](https://github.com/Kuadrant/kuadrant-operator) into an OLM-powered cluster. - -| Flag | Description | -| --------------------- | -------------------------------- | -| `--kubeconfig` string | Kubernetes configuration file | - -* For more information of the Kuadrant Operator, see https://docs.kuadrant.io/kuadrant-operator/ - -#### `uninstall` - -Remove Kuadrant from the cluster. - -| Flag | Description | -| --------------------- | -------------------------------- | -| `--kubeconfig` string | Kubernetes configuration file | - #### `version` Print the version number of `kuadrantctl`. @@ -149,8 +129,6 @@ For more detailed information about each command, including options and usage ex ``` ## Commands -* [Install Kuadrant](doc/install.md) -* [Uninstall Kuadrant](doc/uninstall.md) * [Generate Gateway API HTTPRoute objects from OpenAPI 3.X](doc/generate-gateway-api-httproute.md) * [Generate Kuadrant RateLimitPolicy from OpenAPI 3.X](doc/generate-kuadrant-rate-limit-policy.md) * [Generate Kuadrant AuthPolicy from OpenAPI 3.X](doc/generate-kuadrant-auth-policy.md) diff --git a/cmd/install.go b/cmd/install.go deleted file mode 100644 index c7963e5..0000000 --- a/cmd/install.go +++ /dev/null @@ -1,243 +0,0 @@ -package cmd - -import ( - "context" - "flag" - "fmt" - "time" - - operators "github.com/operator-framework/api/pkg/operators/v1alpha1" - "github.com/spf13/cobra" - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes/scheme" - - kuadrantoperator "github.com/kuadrant/kuadrant-operator/api/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/config" - logf "sigs.k8s.io/controller-runtime/pkg/log" - - "github.com/kuadrant/kuadrantctl/pkg/utils" -) - -var ( - installKubeConfig string - // TODO(eastizle): namespace from command line param - installNamespace string = "kuadrant-system" -) - -const ( - KUADRANT_OPERATOR_VERSION string = "v0.4.1" -) - -func installCommand() *cobra.Command { - installCmd := &cobra.Command{ - Use: "install", - Short: "Install Kuadrant", - Long: "The install command installs kuadrant in a OLM powered cluster", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // Required to have controller-runtim config package read the kubeconfig arg - err := flag.CommandLine.Parse([]string{"-kubeconfig", installKubeConfig}) - if err != nil { - return err - } - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { - return installRun(cmd, args) - }, - } - - // TODO(eastizle): add context flag to switch between kubeconfig contexts - // It would require using config.GetConfigWithContext(context string) (*rest.Config, error) - installCmd.PersistentFlags().StringVarP(&installKubeConfig, "kubeconfig", "", "", "Kubernetes configuration file") - return installCmd -} - -func installRun(cmd *cobra.Command, args []string) error { - err := utils.SetupScheme() - if err != nil { - return err - } - - configuration, err := config.GetConfig() - if err != nil { - return err - } - - k8sClient, err := client.New(configuration, client.Options{Scheme: scheme.Scheme}) - if err != nil { - return err - } - - err = deployKuadrantOperator(k8sClient) - if err != nil { - return err - } - - err = createNamespace(k8sClient) - if err != nil { - return err - } - - err = deployKuadrant(k8sClient) - if err != nil { - return err - } - - return nil -} - -func waitForDeployments(k8sClient client.Client) error { - retryInterval := time.Second * 5 - timeout := time.Minute * 2 - - deploymentKeys := []types.NamespacedName{ - types.NamespacedName{Name: "authorino", Namespace: installNamespace}, - types.NamespacedName{Name: "limitador-limitador", Namespace: installNamespace}, - } - - for _, key := range deploymentKeys { - immediate := true - err := wait.PollUntilContextTimeout(context.Background(), retryInterval, timeout, immediate, func(ctx context.Context) (bool, error) { - return utils.CheckDeploymentAvailable(ctx, k8sClient, key) - }) - - if err != nil { - return err - } - } - - return nil -} - -func deployKuadrantOperator(k8sClient client.Client) error { - logf.Log.Info("Installing kuadrant operator", "version", KUADRANT_OPERATOR_VERSION) - - //apiVersion: operators.coreos.com/v1alpha1 - //kind: Subscription - //metadata: - // name: my-kuadrant-operator - // namespace: operators - //spec: - // channel: stable - // name: kuadrant-operator - // source: operatorhubio-catalog - // sourceNamespace: olm - // - subs := &operators.Subscription{ - TypeMeta: metav1.TypeMeta{APIVersion: "operators.coreos.com/v1alpha1", Kind: "Subscription"}, - ObjectMeta: metav1.ObjectMeta{Name: "kuadrant-operator", Namespace: "operators"}, - Spec: &operators.SubscriptionSpec{ - Channel: "stable", - Package: "kuadrant-operator", - CatalogSource: "operatorhubio-catalog", - CatalogSourceNamespace: "olm", - StartingCSV: fmt.Sprintf("kuadrant-operator.%s", KUADRANT_OPERATOR_VERSION), - }, - } - - err := utils.CreateOnlyK8SObject(k8sClient, subs) - if err != nil { - return err - } - - var installPlanKey client.ObjectKey - - // Wait for the install process to be completed - immediate := true - logf.Log.Info("Waiting for the kuadrant operator installation") - err = wait.PollUntilContextTimeout(context.Background(), time.Second*5, time.Minute*2, immediate, func(ctx context.Context) (bool, error) { - existingSubs := &operators.Subscription{} - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(subs), existingSubs) - if err != nil { - if apierrors.IsNotFound(err) { - logf.Log.Info("Subscription not available", "name", client.ObjectKeyFromObject(subs)) - return false, nil - } - return false, err - } - - if existingSubs.Status.Install == nil || existingSubs.Status.Install.Name == "" { - return false, nil - } - - installPlanKey = client.ObjectKey{ - Name: existingSubs.Status.Install.Name, - Namespace: subs.Namespace, - } - - return true, nil - }) - - if err != nil { - return err - } - - logf.Log.Info("Waiting for the install plan", "name", installPlanKey) - err = wait.PollUntilContextTimeout(context.Background(), time.Second*5, time.Minute*2, immediate, func(ctx context.Context) (bool, error) { - ip := &operators.InstallPlan{} - err := k8sClient.Get(ctx, installPlanKey, ip) - if err != nil { - if apierrors.IsNotFound(err) { - logf.Log.Info("Install plan not available", "name", installPlanKey) - return false, nil - } - return false, err - } - - if ip.Status.Phase != operators.InstallPlanPhaseComplete { - logf.Log.Info("Install plan not ready", "phase", ip.Status.Phase) - return false, nil - } - - return true, nil - }) - - if err != nil { - return err - } - - return nil -} - -func deployKuadrant(k8sClient client.Client) error { - kuadrant := &kuadrantoperator.Kuadrant{ - TypeMeta: metav1.TypeMeta{APIVersion: "kuadrant.io/v1beta1", Kind: "Kuadrant"}, - ObjectMeta: metav1.ObjectMeta{Name: "kuadrant", Namespace: installNamespace}, - Spec: kuadrantoperator.KuadrantSpec{}, - } - - err := utils.CreateOnlyK8SObject(k8sClient, kuadrant) - if err != nil { - return err - } - - return waitForDeployments(k8sClient) -} - -func createNamespace(k8sClient client.Client) error { - nsObj := &corev1.Namespace{ - TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Namespace"}, - ObjectMeta: metav1.ObjectMeta{Name: installNamespace}, - } - logf.Log.Info("Creating kuadrant namespace", "name", installNamespace) - err := utils.CreateOnlyK8SObject(k8sClient, nsObj) - if err != nil { - return err - } - - retryInterval := time.Second * 2 - timeout := time.Second * 20 - immediate := true - return wait.PollUntilContextTimeout(context.Background(), retryInterval, timeout, immediate, func(ctx context.Context) (bool, error) { - err := k8sClient.Get(ctx, types.NamespacedName{Name: installNamespace}, &corev1.Namespace{}) - if err != nil && apierrors.IsNotFound(err) { - return false, nil - } - return true, err - }) -} diff --git a/cmd/root.go b/cmd/root.go index 05b116c..6822ecc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -40,8 +40,6 @@ func GetRootCmd(args []string) *cobra.Command { rootCmd.SilenceUsage = true rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output") - rootCmd.AddCommand(installCommand()) - rootCmd.AddCommand(uninstallCommand()) rootCmd.AddCommand(versionCommand()) rootCmd.AddCommand(generateCommand()) diff --git a/cmd/uninstall.go b/cmd/uninstall.go deleted file mode 100644 index f26df90..0000000 --- a/cmd/uninstall.go +++ /dev/null @@ -1,80 +0,0 @@ -package cmd - -import ( - "flag" - - "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes/scheme" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/config" - logf "sigs.k8s.io/controller-runtime/pkg/log" - - kuadrantoperator "github.com/kuadrant/kuadrant-operator/api/v1beta1" - "github.com/kuadrant/kuadrantctl/pkg/utils" -) - -func uninstallCommand() *cobra.Command { - unInstallCmd := &cobra.Command{ - Use: "uninstall", - Short: "Uninstalling kuadrant from the cluster", - Long: "The uninstall command removes kuadrant manifest bundle from the cluster.", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // Required to have controller-runtim config package read the kubeconfig arg - err := flag.CommandLine.Parse([]string{"-kubeconfig", installKubeConfig}) - if err != nil { - return err - } - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { - return unInstallRun(cmd, args) - }, - } - - // TODO(eastizle): add context flag to switch between kubeconfig contexts - // It would require using config.GetConfigWithContext(context string) (*rest.Config, error) - unInstallCmd.PersistentFlags().StringVarP(&installKubeConfig, "kubeconfig", "", "", "Kubernetes configuration file") - - return unInstallCmd -} - -func unInstallRun(cmd *cobra.Command, args []string) error { - err := utils.SetupScheme() - if err != nil { - return err - } - - configuration, err := config.GetConfig() - if err != nil { - return err - } - - k8sClient, err := client.New(configuration, client.Options{Scheme: scheme.Scheme}) - if err != nil { - return err - } - - err = unDeployKuadrant(k8sClient) - if err != nil { - return err - } - - logf.Log.Info("kuadrant successfully uninstalled") - - return nil -} - -func unDeployKuadrant(k8sClient client.Client) error { - kuadrant := &kuadrantoperator.Kuadrant{ - TypeMeta: metav1.TypeMeta{APIVersion: "kuadrant.io/v1beta1", Kind: "Kuadrant"}, - ObjectMeta: metav1.ObjectMeta{Name: "kuadrant", Namespace: installNamespace}, - } - - err := utils.DeleteK8SObject(k8sClient, kuadrant) - if err != nil { - return err - } - - return nil -} diff --git a/doc/generate-kuadrant-auth-policy.md b/doc/generate-kuadrant-auth-policy.md index 71a1b7c..22fe43d 100644 --- a/doc/generate-kuadrant-auth-policy.md +++ b/doc/generate-kuadrant-auth-policy.md @@ -211,11 +211,9 @@ git clone https://github.com/Kuadrant/kuadrantctl.git cd kuadrantctl ``` -* Setup cluster, istio and Gateway API CRDs +* Setup a cluster, Istio and Gateway API CRDs and Kuadrant -```bash -make local-setup -``` +Use our single-cluster quick start script - this will install Kuadrant in a local `kind` cluster: https://docs.kuadrant.io/getting-started-single-cluster/ * Build and install CLI in `bin/kuadrantctl` path @@ -223,12 +221,6 @@ make local-setup make install ``` -* Install Kuadrant service protection. The CLI can be used to install kuadrant v0.4.1 - -```bash -bin/kuadrantctl install -``` - * Deploy petstore backend API ```bash @@ -493,7 +485,3 @@ it should be a query string named `snake_token` and the token needs to be valid curl -H 'Host: example.com' -i "http://127.0.0.1:9080/api/v1/snake?snake_token=I_LIKE_SNAKES" ``` -* Clean environment -```bash -make local-cleanup -``` diff --git a/doc/generate-kuadrant-rate-limit-policy.md b/doc/generate-kuadrant-rate-limit-policy.md index cbf185f..afb4a48 100644 --- a/doc/generate-kuadrant-rate-limit-policy.md +++ b/doc/generate-kuadrant-rate-limit-policy.md @@ -37,18 +37,15 @@ Global Flags: git clone https://github.com/Kuadrant/kuadrantctl.git cd kuadrantctl ``` -* Setup cluster, istio and Gateway API CRDs -```bash -make local-setup -``` +* Setup a cluster, Istio and Gateway API CRDs and Kuadrant + +Use our single-cluster quick start script - this will install Kuadrant in a local `kind` cluster: https://docs.kuadrant.io/getting-started-single-cluster/ + * Build and install CLI in `bin/kuadrantctl` path ```bash make install ``` -* Install Kuadrant service protection. The CLI can be used to install kuadrant v0.4.1 -```bash -bin/kuadrantctl install -``` + * Deploy petstore backend API ```bash kubectl create namespace petstore diff --git a/doc/install.md b/doc/install.md deleted file mode 100644 index 23e57dc..0000000 --- a/doc/install.md +++ /dev/null @@ -1,23 +0,0 @@ -## Install Kuadrant - -The install command installs kuadrant in a OLM powered cluster. - -Using [Kuadrant Operator v0.4.1](https://github.com/Kuadrant/kuadrant-operator/releases/tag/v0.4.1) -as the installation procedure. - -### Usage : - -```shell -$ kuadrantctl install --help -The install command installs kuadrant in a OLM powered cluster - -Usage: - kuadrantctl install [flags] - -Flags: - -h, --help help for install - --kubeconfig string Kubernetes configuration file - -Global Flags: - -v, --verbose verbose output -``` diff --git a/doc/kuadrantctl-ci-cd.md b/doc/kuadrantctl-ci-cd.md index 6482f26..a721c84 100644 --- a/doc/kuadrantctl-ci-cd.md +++ b/doc/kuadrantctl-ci-cd.md @@ -86,15 +86,11 @@ spec: - name: run-kuadrantctl image: alpine:latest script: | - # Install yq silently - apk add --no-cache curl > /dev/null - curl -s -L https://github.com/mikefarah/yq/releases/download/v4.6.1/yq_linux_arm64 -o /usr/bin/yq > /dev/null && chmod +x /usr/bin/yq - cd $(workspaces.source.path) mkdir -p generated-resources - ./kuadrantctl generate kuadrant authpolicy --oas openapi.yaml | yq eval -P | tee generated-resources/authpolicy.yaml - ./kuadrantctl generate kuadrant ratelimitpolicy --oas openapi.yaml | yq eval -P | tee generated-resources/ratelimitpolicy.yaml - ./kuadrantctl generate gatewayapi httproute --oas openapi.yaml | yq eval -P | tee generated-resources/httproute.yaml + ./kuadrantctl generate kuadrant authpolicy --oas openapi.yaml | tee generated-resources/authpolicy.yaml + ./kuadrantctl generate kuadrant ratelimitpolicy --oas openapi.yaml | tee generated-resources/ratelimitpolicy.yaml + ./kuadrantctl generate gatewayapi httproute --oas openapi.yaml | tee generated-resources/httproute.yaml - name: apply-resources image: lachlanevenson/k8s-kubectl script: | diff --git a/doc/uninstall.md b/doc/uninstall.md deleted file mode 100644 index 3f9a668..0000000 --- a/doc/uninstall.md +++ /dev/null @@ -1,18 +0,0 @@ -## Uninstall Kuadrant - -### Usage : - -```shell -$ kuadrantctl uninstall -h -The uninstall command removes kuadrant from the cluster. - -Usage: - kuadrantctl uninstall [flags] - -Flags: - -h, --help help for uninstall - --kubeconfig string Kubernetes configuration file - -Global Flags: - -v, --verbose verbose output -```