-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christian Hernandez <christian@chernand.io>
- Loading branch information
1 parent
0e55908
commit c5f5a03
Showing
7 changed files
with
278 additions
and
563 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
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
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,110 @@ | ||
/* | ||
Copyright © 2022 Christian Hernandez <christian@chernand.io> | ||
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 ( | ||
"context" | ||
"os" | ||
|
||
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" | ||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" | ||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/tools/clientcmd" | ||
client "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// scanCmd represents the scan command | ||
var scanCmd = &cobra.Command{ | ||
Use: "scan", | ||
Short: "Looks for all HelmReleases and Kustomizations", | ||
Long: `Looks for HelmReleases and Kustomizations in the cluster and | ||
displays the results. | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Set up table | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.AppendHeader(table.Row{"Kind", "Name", "Namespace", "Status"}) | ||
|
||
// Set up the default context | ||
ctx := context.TODO() | ||
|
||
// Get the Kubeconfig to use | ||
kubeConfig, err := cmd.Flags().GetString("kubeconfig") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Set up the schema because HelmRelease and Kustomization are CRDs | ||
kScheme := runtime.NewScheme() | ||
kustomizev1.AddToScheme(kScheme) | ||
sourcev1.AddToScheme(kScheme) | ||
helmv2.AddToScheme(kScheme) | ||
sourcev1.AddToScheme(kScheme) | ||
|
||
// create rest config using the kubeconfig file. | ||
restConfig, err := clientcmd.BuildConfigFromFlags("", kubeConfig) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a new client based on the restconfig and scheme | ||
k, err := client.New(restConfig, client.Options{ | ||
Scheme: kScheme, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Get all Helm Releases in the cluster | ||
helmReleaseList := &helmv2.HelmReleaseList{} | ||
if err = k.List(ctx, helmReleaseList); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Add all Helm Releases to the table | ||
for _, hr := range helmReleaseList.Items { | ||
t.AppendRow(table.Row{"HelmRelease", hr.Name, hr.Namespace, hr.Status.Conditions[0].Message}) | ||
} | ||
|
||
// Add a separotor to the table | ||
t.AppendSeparator() | ||
|
||
// Get all Kustomizations in the cluster | ||
kustomizationList := &kustomizev1.KustomizationList{} | ||
if err = k.List(ctx, kustomizationList); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Add all Kustomizations to the table | ||
for _, k := range kustomizationList.Items { | ||
t.AppendRow(table.Row{"Kustomization", k.Name, k.Namespace, k.Status.Conditions[0].Message}) | ||
} | ||
|
||
//Render the table to the console | ||
t.SetStyle(table.StyleLight) | ||
t.Render() | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(scanCmd) | ||
} |
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,86 +1,86 @@ | ||
module github.com/christianh814/mta | ||
|
||
go 1.18 | ||
go 1.19 | ||
|
||
require ( | ||
github.com/Masterminds/sprig/v3 v3.2.2 | ||
github.com/fluxcd/helm-controller/api v0.22.1 | ||
github.com/fluxcd/source-controller/api v0.25.5 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/spf13/cobra v1.4.0 | ||
github.com/spf13/viper v1.12.0 | ||
k8s.io/apimachinery v0.24.1 | ||
k8s.io/client-go v0.24.1 | ||
sigs.k8s.io/controller-runtime v0.12.1 | ||
github.com/fluxcd/helm-controller/api v0.27.0 | ||
github.com/fluxcd/kustomize-controller/api v0.31.0 | ||
github.com/fluxcd/source-controller/api v0.32.1 | ||
github.com/jedib0t/go-pretty/v6 v6.4.2 | ||
github.com/sirupsen/logrus v1.9.0 | ||
github.com/spf13/cobra v1.6.1 | ||
github.com/spf13/viper v1.14.0 | ||
k8s.io/apimachinery v0.25.4 | ||
k8s.io/client-go v0.25.4 | ||
sigs.k8s.io/controller-runtime v0.13.1 | ||
sigs.k8s.io/yaml v1.3.0 | ||
) | ||
|
||
require ( | ||
github.com/Masterminds/goutils v1.1.1 // indirect | ||
github.com/Masterminds/semver/v3 v3.1.1 // indirect | ||
github.com/PuerkitoBio/purell v1.1.1 // indirect | ||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect | ||
github.com/emicklei/go-restful v2.9.5+incompatible // indirect | ||
github.com/evanphx/json-patch v4.12.0+incompatible // indirect | ||
github.com/fluxcd/pkg/apis/acl v0.0.3 // indirect | ||
github.com/fluxcd/pkg/apis/kustomize v0.4.2 // indirect | ||
github.com/fluxcd/pkg/apis/meta v0.14.2 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/go-restful/v3 v3.8.0 // indirect | ||
github.com/evanphx/json-patch/v5 v5.6.0 // indirect | ||
github.com/fluxcd/pkg/apis/acl v0.1.0 // indirect | ||
github.com/fluxcd/pkg/apis/kustomize v0.7.0 // indirect | ||
github.com/fluxcd/pkg/apis/meta v0.18.0 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.19.5 // indirect | ||
github.com/go-openapi/swag v0.19.14 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/uuid v1.1.2 // indirect | ||
github.com/huandu/xstrings v1.3.1 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mitchellh/copystructure v1.0.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.0 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/shopspring/decimal v1.2.0 // indirect | ||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect | ||
k8s.io/api v0.24.1 // indirect | ||
k8s.io/apiextensions-apiserver v0.24.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fluxcd/kustomize-controller/api v0.26.1 | ||
github.com/fsnotify/fsnotify v1.5.4 // indirect | ||
github.com/go-logr/logr v1.2.2 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/google/uuid v1.1.2 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/huandu/xstrings v1.3.1 // indirect | ||
github.com/imdario/mergo v0.3.12 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.1 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mattn/go-runewidth v0.0.13 // indirect | ||
github.com/mitchellh/copystructure v1.0.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect | ||
github.com/spf13/afero v1.8.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/shopspring/decimal v1.2.0 // indirect | ||
github.com/spf13/afero v1.9.2 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.3.0 // indirect | ||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect | ||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect | ||
github.com/subosito/gotenv v1.4.1 // indirect | ||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect | ||
golang.org/x/net v0.2.0 // indirect | ||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect | ||
golang.org/x/sys v0.2.0 // indirect | ||
golang.org/x/term v0.2.0 // indirect | ||
golang.org/x/text v0.4.0 // indirect | ||
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/ini.v1 v1.66.4 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0 // indirect | ||
k8s.io/klog/v2 v2.60.1 // indirect | ||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect | ||
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect | ||
sigs.k8s.io/yaml v1.3.0 | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/api v0.25.4 // indirect | ||
k8s.io/apiextensions-apiserver v0.25.4 // indirect | ||
k8s.io/klog/v2 v2.80.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect | ||
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 // indirect | ||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
) |
Oops, something went wrong.