Skip to content

Commit

Permalink
liqoctl: add create VirtualNode command
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli committed Aug 8, 2023
1 parent eff85ad commit a79b7f1
Show file tree
Hide file tree
Showing 14 changed files with 607 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/liqoctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ import (
"k8s.io/klog/v2"
"k8s.io/kubectl/pkg/cmd/util"

"github.com/liqotech/liqo/pkg/liqoctl/create"
"github.com/liqotech/liqo/pkg/liqoctl/delete"
"github.com/liqotech/liqo/pkg/liqoctl/factory"
"github.com/liqotech/liqo/pkg/liqoctl/rest"
"github.com/liqotech/liqo/pkg/liqoctl/virtualnode"
)

var liqoctl string

var liqoResources = []rest.APIProvider{
virtualnode.VirtualNode,
}

func init() {
liqoctl = os.Args[0]

Expand Down Expand Up @@ -117,6 +125,8 @@ func NewRootCommand(ctx context.Context) *cobra.Command {
cmd.AddCommand(newMoveCommand(ctx, f))
cmd.AddCommand(newVersionCommand(ctx, f))
cmd.AddCommand(newDocsCommand(ctx))
cmd.AddCommand(create.NewCreateCommand(ctx, liqoResources, f))
cmd.AddCommand(delete.NewDeleteCommand(ctx, liqoResources, f))
return cmd
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/liqoctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
netv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
offloadingv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1"
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
virtualkubeletv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
liqocmd "github.com/liqotech/liqo/cmd/liqoctl/cmd"
)

Expand All @@ -36,6 +37,7 @@ func init() {
utilruntime.Must(netv1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(offloadingv1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(sharingv1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(virtualkubeletv1alpha1.AddToScheme(scheme.Scheme))
}

func main() {
Expand Down
16 changes: 16 additions & 0 deletions pkg/liqoctl/create/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package create contains the implementation of the 'create' command
package create
51 changes: 51 additions & 0 deletions pkg/liqoctl/create/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package create

import (
"context"

"github.com/spf13/cobra"

"github.com/liqotech/liqo/pkg/liqoctl/factory"
"github.com/liqotech/liqo/pkg/liqoctl/rest"
)

func NewCreateCommand(ctx context.Context, liqoResources []rest.APIProvider, f *factory.Factory) *cobra.Command {
options := &rest.CreateOptions{
Factory: f,
}

cmd := &cobra.Command{
Use: "create",
Short: "Create Liqo resources",
Long: "Create Liqo resources.",
Args: cobra.NoArgs,
}

cmd.PersistentFlags().StringVarP(&options.Namespace, "namespace", "n", "default",
"The namespace where the resource will be created")

for _, r := range liqoResources {
api := r()

apiOptions := api.APIOptions()
if apiOptions.EnableCreate {
cmd.AddCommand(api.Create(ctx, options))
}
}

return cmd
}
16 changes: 16 additions & 0 deletions pkg/liqoctl/delete/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package delete contains the implementation of the 'delete' command
package delete
51 changes: 51 additions & 0 deletions pkg/liqoctl/delete/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package delete

import (
"context"

"github.com/spf13/cobra"

"github.com/liqotech/liqo/pkg/liqoctl/factory"
"github.com/liqotech/liqo/pkg/liqoctl/rest"
)

func NewDeleteCommand(ctx context.Context, liqoResources []rest.APIProvider, f *factory.Factory) *cobra.Command {
options := &rest.DeleteOptions{
Factory: f,
}

cmd := &cobra.Command{
Use: "delete",
Short: "Delete Liqo resources",
Long: "Delete Liqo resources.",
Args: cobra.NoArgs,
}

cmd.PersistentFlags().StringVarP(&options.Namespace, "namespace", "n", "default",
"The namespace where the resource will be deleted")

for _, r := range liqoResources {
api := r()

apiOptions := api.APIOptions()
if apiOptions.EnableDelete {
cmd.AddCommand(api.Delete(ctx, options))
}
}

return cmd
}
16 changes: 16 additions & 0 deletions pkg/liqoctl/rest/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package rest contains the types and interfaces to interact with the Liqo API.
package rest
61 changes: 61 additions & 0 deletions pkg/liqoctl/rest/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rest

import (
"context"

"github.com/spf13/cobra"

"github.com/liqotech/liqo/pkg/liqoctl/factory"
)

type APIOptions struct {
EnableCreate bool
EnableDelete bool
EnableGet bool
EnableUpdate bool
}

type CreateOptions struct {
*factory.Factory

OutputFormat string
Name string
}

type DeleteOptions struct {
*factory.Factory

Name string
}

type GetOptions struct {
*factory.Factory
}

type UpdateOptions struct {
*factory.Factory
}

type API interface {
APIOptions() *APIOptions
Create(ctx context.Context, options *CreateOptions) *cobra.Command
Delete(ctx context.Context, options *DeleteOptions) *cobra.Command
Get(ctx context.Context, options *GetOptions) *cobra.Command
Update(ctx context.Context, options *UpdateOptions) *cobra.Command
}

type APIProvider func() API
Loading

0 comments on commit a79b7f1

Please sign in to comment.