This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wulf-Thilo Schreiter
committed
Apr 19, 2020
1 parent
e0c1da7
commit a166a01
Showing
34 changed files
with
315 additions
and
13,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: go | ||
go: | ||
- 1.12.x | ||
- 1.14.x | ||
env: | ||
- GO111MODULE=on | ||
install: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright © 2020 Bitgrip <[email protected]> | ||
// | ||
// 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 ( | ||
"github.com/bitgrip/cattlectl/internal/pkg/config" | ||
"github.com/bitgrip/cattlectl/internal/pkg/ctl" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var ( | ||
validArgs = []string{"app"} | ||
deleteCmd = &cobra.Command{ | ||
Use: "delete TYPE NAME", | ||
Short: "Deletes an rancher resouce", | ||
Long: "Deletes an rancher resouce", | ||
Run: delete, | ||
ValidArgs: validArgs, | ||
} | ||
rootConfig config.Config | ||
initCommand = func() {} | ||
) | ||
|
||
// BaseCommand is accessor to the package base command | ||
func BaseCommand(config config.Config, init func()) *cobra.Command { | ||
rootConfig = config | ||
initCommand = init | ||
return deleteCmd | ||
} | ||
|
||
func delete(cmd *cobra.Command, args []string) { | ||
if len(args) != 2 { | ||
logrus.Warn(cmd.UsageString()) | ||
return | ||
} | ||
resouceType := args[0] | ||
resourceName := args[1] | ||
projectName := viper.GetString("rancher.project_name") | ||
logrus. | ||
WithField("project-name", projectName). | ||
WithField("resouce-type", resouceType). | ||
WithField("resouce-name", resourceName). | ||
WithField("cluster-name", rootConfig.ClusterName()). | ||
Info("Delete project resouce") | ||
err := ctl.DeleteProjectResouce(projectName, resouceType, resourceName, rootConfig) | ||
if err != nil { | ||
logrus. | ||
WithField("project-name", projectName). | ||
WithField("resouce-type", resouceType). | ||
WithField("resouce-name", resourceName). | ||
WithField("cluster-name", rootConfig.ClusterName()). | ||
Fatal(err) | ||
} | ||
} | ||
|
||
func init() { | ||
|
||
deleteCmd.PersistentFlags().String("project-name", "", "The name of the project to delete resouces from") | ||
viper.BindPFlag("rancher.project_name", deleteCmd.PersistentFlags().Lookup("project-name")) | ||
viper.BindEnv("rancher.project_name", "RANCHER_PROJECT_NAME") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## cattlectl delete | ||
|
||
Deletes an rancher resouce | ||
|
||
### Synopsis | ||
|
||
Deletes an rancher resouce | ||
|
||
``` | ||
cattlectl delete TYPE NAME [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for delete | ||
--project-name string The name of the project to delete resouces from | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--access-key string The access key to access rancher with | ||
--cluster-id string The ID of the cluster the project is part of | ||
--cluster-name string The name of the cluster the project is part of | ||
--config string config file (default is $HOME/.cattlectl.yaml) | ||
--insecure-api If Rancher uses a self signed certificate | ||
--log-json if to log using json format | ||
--rancher-url string The URL to reach the rancher | ||
--secret-key string The secret key to access rancher with | ||
-v, --verbosity int verbosity level to use | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [cattlectl](cattlectl.md) - controll your cattle on the ranch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,24 @@ | ||
module github.com/bitgrip/cattlectl | ||
|
||
go 1.14 | ||
|
||
require ( | ||
cloud.google.com/go v0.39.0 // indirect | ||
github.com/766b/go-outliner v0.0.0-20180511142203-fc6edecdadd7 // indirect | ||
github.com/Masterminds/semver v1.4.2 | ||
github.com/NYTimes/gziphandler v1.1.1 // indirect | ||
github.com/OneOfOne/xxhash v1.2.5 // indirect | ||
github.com/PuerkitoBio/purell v1.1.1 // indirect | ||
github.com/coreos/etcd v3.3.13+incompatible // indirect | ||
github.com/coreos/go-semver v0.3.0 // indirect | ||
github.com/dgryski/go-sip13 v0.0.0-20190329191031-25c5027a8c7b // indirect | ||
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect | ||
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect | ||
github.com/emicklei/go-restful v2.9.6+incompatible // indirect | ||
github.com/evanphx/json-patch v4.2.0+incompatible // indirect | ||
github.com/go-openapi/jsonpointer v0.19.0 // indirect | ||
github.com/go-openapi/jsonreference v0.19.0 // indirect | ||
github.com/go-openapi/spec v0.19.0 // indirect | ||
github.com/go-openapi/swag v0.19.0 // indirect | ||
github.com/golang/mock v1.3.1 // indirect | ||
github.com/google/gofuzz v1.0.0 // indirect | ||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f // indirect | ||
github.com/google/uuid v1.1.1 // indirect | ||
github.com/googleapis/gnostic v0.2.0 // indirect | ||
github.com/hhatto/gocloc v0.2.1 // indirect | ||
github.com/jessevdk/go-flags v1.4.0 // indirect | ||
github.com/json-iterator/go v1.1.6 // indirect | ||
github.com/kisielk/errcheck v1.2.0 // indirect | ||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect | ||
github.com/kr/pty v1.1.4 // indirect | ||
github.com/magiconair/properties v1.8.1 // indirect | ||
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 | ||
github.com/munnerz/goautoneg v0.0.0-20190414153302-2ae31c8b6b30 // indirect | ||
github.com/onsi/ginkgo v1.8.0 // indirect | ||
github.com/onsi/gomega v1.5.0 // indirect | ||
github.com/pelletier/go-toml v1.4.0 // indirect | ||
github.com/pkg/errors v0.8.1 // indirect | ||
github.com/prometheus/common v0.4.1 // indirect | ||
github.com/prometheus/procfs v0.0.2 // indirect | ||
github.com/prometheus/tsdb v0.8.0 // indirect | ||
github.com/rancher/norman v0.0.0-20190529014815-f5744043a6fb | ||
github.com/rancher/types v0.0.0-20190605225901-9125ab265f1b | ||
github.com/rogpeppe/fastuuid v1.1.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.0.1 // indirect | ||
github.com/sergi/go-diff v1.0.0 | ||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | ||
github.com/sirupsen/logrus v1.4.2 | ||
github.com/spaolacci/murmur3 v1.1.0 // indirect | ||
github.com/spf13/afero v1.2.2 | ||
github.com/spf13/cobra v0.0.4 | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/viper v1.4.0 | ||
github.com/stretchr/objx v0.2.0 // indirect | ||
github.com/toqueteos/trie v1.0.0 // indirect | ||
github.com/ugorji/go v1.1.5-pre // indirect | ||
go.opencensus.io v0.22.0 // indirect | ||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 // indirect | ||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522 // indirect | ||
golang.org/x/image v0.0.0-20190523035834-f03afa92d3ff // indirect | ||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect | ||
golang.org/x/mobile v0.0.0-20190509164839-32b2708ab171 // indirect | ||
golang.org/x/mod v0.1.0 // indirect | ||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65 // indirect | ||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect | ||
golang.org/x/sys v0.0.0-20190606122018-79a91cf218c4 // indirect | ||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b // indirect | ||
google.golang.org/appengine v1.6.0 // indirect | ||
google.golang.org/genproto v0.0.0-20190605220351-eb0b1bdb6ae6 // indirect | ||
google.golang.org/grpc v1.21.1 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/src-d/enry.v1 v1.7.3 // indirect | ||
gopkg.in/toqueteos/substring.v1 v1.0.2 // indirect | ||
gopkg.in/yaml.v2 v2.2.2 | ||
honnef.co/go/tools v0.0.0-20190605142022-0a11fc526260 // indirect | ||
k8s.io/apimachinery v0.0.0-20190602183612-63a6072eb563 | ||
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a // indirect | ||
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// 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 ctl | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bitgrip/cattlectl/internal/pkg/config" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
deletableProjectResouceTypes = map[string]func(string, string, config.Config) error{ | ||
"app": deleteApp, | ||
} | ||
) | ||
|
||
func DeleteProjectResouce(projectName, resouceType, name string, config config.Config) (err error) { | ||
deleteFunc, supportedType := deletableProjectResouceTypes[resouceType] | ||
if !supportedType { | ||
return fmt.Errorf("Not supported resouce type [%s]", resouceType) | ||
} | ||
return deleteFunc(projectName, name, config) | ||
} | ||
|
||
func deleteApp(projectName, name string, config config.Config) (err error) { | ||
_, _, projectClient, err := getProjectClient(projectName, config) | ||
if err != nil { | ||
return | ||
} | ||
|
||
app, err := projectClient.App(name) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if exists, err := app.Exists(); err != nil || !exists { | ||
if err != nil { | ||
return err | ||
} | ||
logrus. | ||
WithField("project-name", projectName). | ||
WithField("resouce-name", name). | ||
WithField("cluster-name", config.ClusterName()). | ||
Info("No app skip delete") | ||
return nil | ||
} | ||
|
||
err = app.Delete() | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// 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 ctl | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bitgrip/cattlectl/internal/pkg/config" | ||
rancher_client "github.com/bitgrip/cattlectl/internal/pkg/rancher/client" | ||
) | ||
|
||
var ( | ||
getRancherClient = doGetRancherClient | ||
getClusterClient = doGetClusterClient | ||
getProjectClient = doGetProjectClient | ||
) | ||
|
||
func doGetProjectClient(projectName string, config config.Config) (rancherClient rancher_client.RancherClient, clusterClient rancher_client.ClusterClient, projectClient rancher_client.ProjectClient, err error) { | ||
rancherClient, clusterClient, err = getClusterClient(config) | ||
if err != nil { | ||
return | ||
} | ||
projectClient, err = clusterClient.Project(projectName) | ||
if err != nil { | ||
return | ||
} | ||
if exists, err := projectClient.Exists(); err != nil || !exists { | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
return nil, nil, nil, fmt.Errorf("Project not found [%s]", projectName) | ||
} | ||
return | ||
} | ||
|
||
func doGetClusterClient(config config.Config) (rancherClient rancher_client.RancherClient, clusterClient rancher_client.ClusterClient, err error) { | ||
rancherClient, err = getRancherClient(config) | ||
if err != nil { | ||
return | ||
} | ||
clusterClient, err = rancherClient.Cluster(config.ClusterName()) | ||
if err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
func doGetRancherClient(config config.Config) (rancherClient rancher_client.RancherClient, err error) { | ||
rancherClient, err = newRancherClient(rancher_client.RancherConfig{ | ||
RancherURL: config.RancherURL(), | ||
AccessKey: config.AccessKey(), | ||
SecretKey: config.SecretKey(), | ||
Insecure: config.InsecureAPI(), | ||
CACerts: config.CACerts(), | ||
MergeAnswers: config.MergeAnswers(), | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
return | ||
} |
Oops, something went wrong.