Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cmd/kube_ippool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/outscale/goutils/oks/clientset"
oksv1beta "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta"
"github.com/spf13/cobra"
)

// oksCmd represents the kubecommand
var ippoolCmd = &cobra.Command{
GroupID: "service",
Use: "ippool",
Short: "ippool commands",
}

func init() {
buildKubeAPI("kubeclient_ippool", ippoolCmd, oksCmd, func(client *clientset.Clientset) oksv1beta.IPPoolInterface {
return client.OksV1beta().IPPools()
})
}
35 changes: 32 additions & 3 deletions cmd/kube_kubeapi.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
package cmd

import (
"reflect"
"slices"

"github.com/outscale/goutils/oks/clientset"
oksv1beta2 "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta2"
"github.com/outscale/octl/pkg/builder"
"github.com/outscale/octl/pkg/config"
"github.com/outscale/octl/pkg/flags"
"github.com/outscale/octl/pkg/messages"
"github.com/outscale/octl/pkg/preferences"
"github.com/outscale/octl/pkg/runner"
"github.com/outscale/osc-sdk-go/v3/pkg/oks"
"github.com/outscale/osc-sdk-go/v3/pkg/osc"
"github.com/samber/lo"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
)

func kubeapi(provider string) func(cmd *cobra.Command, args []string) {
func buildKubeAPI[Client any](provider string, cmd, parent *cobra.Command, getclient func(client *clientset.Clientset) Client) {
parent.AddCommand(cmd)
b := builder.NewBuilder[Client](provider, "https://docs.outscale.com/api.html")
b.BuildAPI(cmd, func(m reflect.Method) bool {
return slices.Contains([]string{"List", "Get", "Create", "Update", "Delete"}, m.Name)
}, runKubeAPI(func(cmd *cobra.Command, args []string, client *clientset.Clientset) error {
return runner.Run[Client, *osc.ErrorResponse](cmd, args, getclient(client), config.For(provider))
}))
apiCmd, _ := lo.Find(cmd.Commands(), func(c *cobra.Command) bool { return c.Name() == "api" })
b.Build(parent, apiCmd)
for _, child := range cmd.Commands() {
if child.Name() == "api" {
child.PersistentFlags().String("cluster", "", "[REQUIRED] ID of cluster")
_ = child.MarkPersistentFlagRequired("cluster")
} else {
child.Flags().String("cluster", "", "[REQUIRED] Name or ID of cluster")
child.Flags().String("project", preferences.Preferences.Kube.DefaultProject, "Name or ID of project")
_ = child.MarkFlagRequired("cluster")
_ = flags.MarkAsNoForward(child.Flags(), "project")
}
}
}

func runKubeAPI(fn func(cmd *cobra.Command, args []string, client *clientset.Clientset) error) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
p := loadProfile(cmd)
cl, err := oks.NewClient(p, sdkOptions(cmd)...)
Expand All @@ -34,7 +63,7 @@ func kubeapi(provider string) func(cmd *cobra.Command, args []string) {
messages.ExitErr(err)
}

err = runner.Run[oksv1beta2.NodePoolInterface, *osc.ErrorResponse](cmd, args, client.OksV1beta2().NodePools(), config.For(provider))
err = fn(cmd, args, client)
if err != nil {
messages.ExitErr(err)
}
Expand Down
20 changes: 20 additions & 0 deletions cmd/kube_netpeering.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/outscale/goutils/oks/clientset"
oksv1beta "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta"
"github.com/spf13/cobra"
)

// oksCmd represents the kubecommand
var netpeeringCmd = &cobra.Command{
GroupID: "service",
Use: "netpeering",
Short: "netpeering commands",
}

func init() {
buildKubeAPI("kubeclient_netpeering", netpeeringCmd, oksCmd, func(client *clientset.Clientset) oksv1beta.NetPeeringInterface {
return client.OksV1beta().NetPeerings()
})
}
20 changes: 20 additions & 0 deletions cmd/kube_netpeeringacceptance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/outscale/goutils/oks/clientset"
oksv1beta "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta"
"github.com/spf13/cobra"
)

// oksCmd represents the kubecommand
var netpeeringacceptanceCmd = &cobra.Command{
GroupID: "service",
Use: "acceptance",
Short: "netpeering acceptance commands",
}

func init() {
buildKubeAPI("kubeclient_netpeeringacceptances", netpeeringacceptanceCmd, netpeeringCmd, func(client *clientset.Clientset) oksv1beta.NetPeeringAcceptanceInterface {
return client.OksV1beta().NetPeeringAcceptances()
})
}
20 changes: 20 additions & 0 deletions cmd/kube_netpeeringrequest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/outscale/goutils/oks/clientset"
oksv1beta "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta"
"github.com/spf13/cobra"
)

// oksCmd represents the kubecommand
var netpeeringrequestCmd = &cobra.Command{
GroupID: "service",
Use: "request",
Short: "netpeering request commands",
}

func init() {
buildKubeAPI("kubeclient_netpeeringrequests", netpeeringrequestCmd, netpeeringCmd, func(client *clientset.Clientset) oksv1beta.NetPeeringRequestInterface {
return client.OksV1beta().NetPeeringRequests()
})
}
29 changes: 4 additions & 25 deletions cmd/kube_nodepool.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package cmd

import (
"reflect"
"slices"

"github.com/outscale/goutils/oks/clientset"
oksv1beta2 "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta2"
"github.com/outscale/octl/pkg/builder"
"github.com/outscale/octl/pkg/flags"
"github.com/outscale/octl/pkg/preferences"
"github.com/samber/lo"
"github.com/spf13/cobra"
)

Expand All @@ -21,22 +15,7 @@ var nodepoolCmd = &cobra.Command{
}

func init() {
oksCmd.AddCommand(nodepoolCmd)
b := builder.NewBuilder[oksv1beta2.NodePoolInterface]("kubeclient_nodepool", "https://docs.outscale.com/api.html")
b.BuildAPI(nodepoolCmd, func(m reflect.Method) bool {
return slices.Contains([]string{"List", "Get", "Create", "Update", "Delete"}, m.Name)
}, kubeapi("kubeclient_nodepool"))
apiCmd, _ := lo.Find(nodepoolCmd.Commands(), func(c *cobra.Command) bool { return c.Name() == "api" })
b.Build(oksCmd, apiCmd)
for _, cmd := range nodepoolCmd.Commands() {
if cmd.Name() == "api" {
cmd.PersistentFlags().String("cluster", "", "[REQUIRED] ID of cluster")
_ = cmd.MarkPersistentFlagRequired("cluster")
} else {
cmd.Flags().String("cluster", "", "[REQUIRED] Name or ID of cluster")
cmd.Flags().String("project", preferences.Preferences.Kube.DefaultProject, "Name or ID of project")
_ = cmd.MarkFlagRequired("cluster")
_ = flags.MarkAsNoForward(cmd.Flags(), "project")
}
}
buildKubeAPI("kubeclient_nodepool", nodepoolCmd, oksCmd, func(client *clientset.Clientset) oksv1beta2.NodePoolInterface {
return client.OksV1beta2().NodePools()
})
}
20 changes: 20 additions & 0 deletions cmd/kube_oosaccess.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/outscale/goutils/oks/clientset"
oksv1beta "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta"
"github.com/spf13/cobra"
)

// oksCmd represents the kubecommand
var oosaccessCmd = &cobra.Command{
GroupID: "service",
Use: "oosaccess",
Short: "oosaccess commands",
}

func init() {
buildKubeAPI("kubeclient_oosaccess", oosaccessCmd, oksCmd, func(client *clientset.Clientset) oksv1beta.OOSAccessInterface {
return client.OksV1beta().OOSAccesses()
})
}
20 changes: 20 additions & 0 deletions cmd/kube_vpnconnection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/outscale/goutils/oks/clientset"
oksv1beta "github.com/outscale/goutils/oks/clientset/typed/oks.dev/v1beta"
"github.com/spf13/cobra"
)

// oksCmd represents the kubecommand
var vpnconnectionCmd = &cobra.Command{
GroupID: "service",
Use: "vpnconnection",
Short: "vpnconnection commands",
}

func init() {
buildKubeAPI("kubeclient_vpnconnection", vpnconnectionCmd, oksCmd, func(client *clientset.Clientset) oksv1beta.VpnConnectionInterface {
return client.OksV1beta().VpnConnections()
})
}
4 changes: 4 additions & 0 deletions docs/reference/octl_kube.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ OUTSCALE Kubernetes as a Service (OKS) management
* [octl](octl.md) - A modern CLI for Outscale services
* [octl kube api](octl_kube_api.md) - kube api calls
* [octl kube cluster](octl_kube_cluster.md) - cluster commands
* [octl kube ippool](octl_kube_ippool.md) - ippool commands
* [octl kube kubectl](octl_kube_kubectl.md) -
* [octl kube netpeering](octl_kube_netpeering.md) - netpeering commands
* [octl kube nodepool](octl_kube_nodepool.md) - nodepool commands
* [octl kube oosaccess](octl_kube_oosaccess.md) - oosaccess commands
* [octl kube project](octl_kube_project.md) - project commands
* [octl kube publicip](octl_kube_publicip.md) - publicip commands
* [octl kube quota](octl_kube_quota.md) - quota commands
* [octl kube secret](octl_kube_secret.md) - Create secret for CCM or CSI driver deployment
* [octl kube vpnconnection](octl_kube_vpnconnection.md) - vpnconnection commands

44 changes: 44 additions & 0 deletions docs/reference/octl_kube_ippool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## octl kube ippool

ippool commands

### Options

```
-h, --help help for ippool
```

### Options inherited from parent commands

```
-c, --columns string columns to display - [+]<title>:<jq query for content>||<title>:<jq query for content>
--config string Path of profile file (by default, ~/.osc/config.json)
--dry-run Display the request payload that would be sent to the API without sending it
--elapsed add elapsed time column when using --watch (default true)
--filter strings comma separated list of filters for results - name:value,name:value, alias for jq filter 'select(.name | tostring | test("value"))'
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
--payload string JSON content for query body
--profile string Profile to use in profile file (by default, "default")
--single convert single entry lists to a single object
--template string JSON template file for query body
-v, --verbose Verbose output
--waitfor string repeatedly call the API until the specified jq expression returns 1/true or a non empty result
--waitfor-timeout duration maximum duration of a wait (default 10m0s)
--watch repeatedly call the API and display changes
-y, --yes answer yes to all prompts
```

### SEE ALSO

* [octl kube](octl_kube.md) - OUTSCALE Kubernetes as a Service (OKS) management
* [octl kube ippool api](octl_kube_ippool_api.md) - ippool api calls
* [octl kube ippool create](octl_kube_ippool_create.md) - alias for request api Create
* [octl kube ippool delete](octl_kube_ippool_delete.md) - alias for api Delete id
* [octl kube ippool describe](octl_kube_ippool_describe.md) - alias for api Get
* [octl kube ippool list](octl_kube_ippool_list.md) - alias for api List

45 changes: 45 additions & 0 deletions docs/reference/octl_kube_ippool_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## octl kube ippool api

ippool api calls

### Options

```
--cluster string [REQUIRED] ID of cluster
-h, --help help for api
```

### Options inherited from parent commands

```
-c, --columns string columns to display - [+]<title>:<jq query for content>||<title>:<jq query for content>
--config string Path of profile file (by default, ~/.osc/config.json)
--dry-run Display the request payload that would be sent to the API without sending it
--elapsed add elapsed time column when using --watch (default true)
--filter strings comma separated list of filters for results - name:value,name:value, alias for jq filter 'select(.name | tostring | test("value"))'
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
--payload string JSON content for query body
--profile string Profile to use in profile file (by default, "default")
--single convert single entry lists to a single object
--template string JSON template file for query body
-v, --verbose Verbose output
--waitfor string repeatedly call the API until the specified jq expression returns 1/true or a non empty result
--waitfor-timeout duration maximum duration of a wait (default 10m0s)
--watch repeatedly call the API and display changes
-y, --yes answer yes to all prompts
```

### SEE ALSO

* [octl kube ippool](octl_kube_ippool.md) - ippool commands
* [octl kube ippool api Create](octl_kube_ippool_api_Create.md) -
* [octl kube ippool api Delete](octl_kube_ippool_api_Delete.md) -
* [octl kube ippool api Get](octl_kube_ippool_api_Get.md) -
* [octl kube ippool api List](octl_kube_ippool_api_List.md) -
* [octl kube ippool api Update](octl_kube_ippool_api_Update.md) -

Loading
Loading