Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/mogenius/punq into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
beneiltis committed Oct 18, 2023
2 parents 834e045 + 0a1aa26 commit e0b9415
Show file tree
Hide file tree
Showing 42 changed files with 101 additions and 45 deletions.
22 changes: 22 additions & 0 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"log"
"os"
"strings"

Expand Down Expand Up @@ -156,10 +157,27 @@ var getContextCmd = &cobra.Command{
fmt.Printf("No context found for '%s'.\n", contextId)
} else {
structs.PrettyPrint(ctx)

}
},
}

var exportNamespaceCmd = &cobra.Command{
Use: "export",
Short: "Export all resources from a specific namespace.",
Long: `The get command lets you get a specific context from punq.`,
Run: func(cmd *cobra.Command, args []string) {
RequireStringFlag(contextId, "context-id")
RequireStringFlag(namespace, "namespace")

resourcesYaml, err := kubernetes.AllResourcesFromToCombinedYaml(namespace, resources, &contextId)
if err != nil {
log.Fatal(err.Error())
}
fmt.Print(resourcesYaml)
},
}

func init() {
contextCmd.AddCommand(listContextCmd)

Expand All @@ -177,5 +195,9 @@ func init() {

contextCmd.AddCommand(getContextCmd)

exportNamespaceCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "A namespace to export resources from")
exportNamespaceCmd.Flags().StringSliceVarP(&resources, "resources", "r", []string{}, "A list of resources to gather separated by comma (,)")
contextCmd.AddCommand(exportNamespaceCmd)

rootCmd.AddCommand(contextCmd)
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var filePath string
var contextId string
var accessLevel string
var forceUpgrade bool
var resources []string

var cmdsWithoutContext = []string{
"punq",
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func DeleteK8sCertificateBy(namespace string, name string, contextId *string) er
}

func DescribeK8sCertificate(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "certificate", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "certificate", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/cluster-role-bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func DeleteK8sClusterRoleBindingBy(name string, contextId *string) error {
}

func DescribeK8sClusterRoleBinding(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "clusterrolebinding", name)
cmd := exec.Command("kubectl", "describe", "clusterrolebinding", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/cluster-roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func DeleteK8sClusterRoleBy(name string, contextId *string) error {
}

func DescribeK8sClusterRole(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "clusterrole", name)
cmd := exec.Command("kubectl", "describe", "clusterrole", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/clusterIssuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sClusterIssuerBy(name string, contextId *string) error {
}

func DescribeK8sClusterIssuer(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "clusterissuer", name)
cmd := exec.Command("kubectl", "describe", "clusterissuer", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func DeleteK8sConfigmapBy(namespaceName string, name string, contextId *string)
}

func DescribeK8sConfigmap(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "configmap", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "configmap", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func DeleteK8sCustomResourceDefinition(data apiExt.CustomResourceDefinition) uti
}

func DescribeK8sCustomResourceDefinition(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "crds", name)
cmd := exec.Command("kubectl", "describe", "crds", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func DeleteK8sCronJobBy(namespace string, name string, contextId *string) error
}

func DescribeK8sCronJob(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "cronjob", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "cronjob", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sCertificateSigningRequestBy(namespace string, name string, context
}

func DescribeK8sCertificateSigningRequest(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "-n", namespace, "csr", name)
cmd := exec.Command("kubectl", "describe", "-n", namespace, "csr", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func DeleteK8sDaemonSetBy(namespace string, name string, contextId *string) erro
}

func DescribeK8sDaemonSet(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "daemonset", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "daemonset", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func DeleteK8sDeploymentBy(namespace string, name string, contextId *string) err
}

func DescribeK8sDeployment(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "deployment", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "deployment", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func DeleteK8sEndpointBy(namespace string, name string, contextId *string) error
}

func DescribeK8sEndpoint(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "endpoint", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "endpoint", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetEvent(namespaceName string, name string, contextId *string) (*v1Core.Eve
}

func DescribeK8sEvent(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "event", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "event", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sHpaBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sHpa(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "hpa", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "hpa", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func DeleteK8sIngressBy(namespace string, name string, contextId *string) error
}

func DescribeK8sIngress(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "ingress", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "ingress", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/ingressClass.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func DeleteK8sIngressClassBy(name string, contextId *string) error {
}

func DescribeK8sIngressClass(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "ingressclass", name)
cmd := exec.Command("kubectl", "describe", "ingressclass", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sIssuerBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sIssuer(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "issuer", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "issuer", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sJobBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sJob(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "job", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "job", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/leases.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func DeleteK8sLeaseBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sLease(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "lease", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "lease", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func DeleteK8sNamespaceBy(name string, contextId *string) error {
}

func DescribeK8sNamespace(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "namespace", name)
cmd := exec.Command("kubectl", "describe", "namespace", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/networkpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sNetworkPolicyBy(namespace string, name string, contextId *string)
}

func DescribeK8sNetworkPolicy(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "netpol", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "netpol", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func DeleteK8sNode(name string, contextId *string) error {
}

func DescribeK8sNode(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "node", name)
cmd := exec.Command("kubectl", "describe", "node", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sOrderBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sOrder(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "order", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "order", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/persistent-volume-claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func DeleteK8sPersistentVolumeClaimBy(namespace string, name string, contextId *
}

func DescribeK8sPersistentVolumeClaim(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "persistentvolumeclaim", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "persistentvolumeclaim", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/persistent-volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func DeleteK8sPersistentVolumeBy(name string, contextId *string) error {
}

func DescribeK8sPersistentVolume(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "persistentvolume", name)
cmd := exec.Command("kubectl", "describe", "persistentvolume", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func DeleteK8sPodBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sPod(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "pod", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "pod", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/priorityclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func DeleteK8sPriorityClassBy(name string, contextId *string) error {
}

func DescribeK8sPriorityClass(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "priorityclasses", name)
cmd := exec.Command("kubectl", "describe", "priorityclasses", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/replicasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func DeleteK8sReplicasetBy(namespace string, name string, contextId *string) err
}

func DescribeK8sReplicaset(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "replicaset", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "replicaset", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resourcequotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func DeleteK8sResourceQuotaBy(namespace string, name string, contextId *string)
}

func DescribeK8sResourceQuota(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "resourcequotas", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "resourcequotas", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/role-bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sRoleBindingBy(namespace string, name string, contextId *string) er
}

func DescribeK8sRoleBinding(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "rolebinding", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "rolebinding", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sRoleBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sRole(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "role", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "role", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func DeleteK8sSecretBy(namespace string, name string, contextId *string) error {
}

func DescribeK8sSecret(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "secret", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "secret", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/service-accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func DeleteK8sServiceAccountBy(namespace string, name string, contextId *string)
}

func DescribeK8sServiceAccount(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "serviceaccount", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "serviceaccount", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func DeleteK8sServiceBy(namespace string, name string, contextId *string) error
}

func DescribeK8sService(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "service", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "service", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/statefulsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DeleteK8sStatefulsetBy(namespace string, name string, contextId *string) er
}

func DescribeK8sStatefulset(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "statefulset", name, "-n", namespace)
cmd := exec.Command("kubectl", "describe", "statefulset", name, "-n", namespace, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/storageClass.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func DeleteK8sStorageClassBy(name string, contextId *string) error {
}

func DescribeK8sStorageClass(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("kubectl", ContextFlag(contextId), "describe", "storageclass", name)
cmd := exec.Command("kubectl", "describe", "storageclass", name, ContextFlag(contextId))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
Loading

0 comments on commit e0b9415

Please sign in to comment.