Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Add 'apply' command. #156

Merged
merged 1 commit into from
Jul 13, 2017
Merged
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
46 changes: 46 additions & 0 deletions cmd/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2017 The Kedge Authors All rights reserved.

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 cmd

import (
"fmt"
pkgcmd "github.com/kedgeproject/kedge/pkg/cmd"
"github.com/spf13/cobra"
"os"
)

// Variables
var (
ApplyFiles []string
)

// Represents the "apply" command
var applyCmd = &cobra.Command{
Use: "apply",
Short: "Apply a configuration to a resource on the Kubernetes cluster. This resource will be created if it doesn't exist yet.",
Run: func(cmd *cobra.Command, args []string) {
if err := pkgcmd.ExecuteKubectl(ApplyFiles, "apply"); err != nil {
fmt.Println(err)
os.Exit(-1)
}
},
}

func init() {
applyCmd.Flags().StringArrayVarP(&ApplyFiles, "files", "f", []string{}, "Specify files")
RootCmd.AddCommand(applyCmd)
}
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var createCmd = &cobra.Command{
Use: "create",
Short: "Create the resource on the Kubernetes cluster",
Run: func(cmd *cobra.Command, args []string) {
if err := pkgcmd.Create(CreateFiles); err != nil {
if err := pkgcmd.ExecuteKubectl(CreateFiles, "create"); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete the resource from the Kubernetes cluster",
Run: func(cmd *cobra.Command, args []string) {
if err := pkgcmd.Delete(DeleteFiles); err != nil {
if err := pkgcmd.ExecuteKubectl(DeleteFiles, "delete"); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand Down
14 changes: 1 addition & 13 deletions pkg/cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,7 @@ import (
"github.com/pkg/errors"
)

func Delete(files []string) error {
return executeKubectl(files, true)
}

func Create(files []string) error {
return executeKubectl(files, false)
}

func executeKubectl(files []string, delete bool) error {
command := "create"
if delete {
command = "delete"
}
func ExecuteKubectl(files []string, command string) error {

appData, err := getApplicationsFromFiles(files)
if err != nil {
Expand Down