Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
beneiltis committed Nov 17, 2023
2 parents a42d929 + c41a8d1 commit 093b000
Show file tree
Hide file tree
Showing 46 changed files with 92 additions and 213 deletions.
24 changes: 0 additions & 24 deletions cmd/exec.go

This file was deleted.

4 changes: 2 additions & 2 deletions kubernetes/addResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ func addTraefikMiddleware(provider *KubeProvider, ingressHostname string) {

var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/C", fmt.Sprintf("kubectl apply -f %s%s", fileName, ContextFlag(nil)))
cmd = utils.RunOnLocalShell(fmt.Sprintf("kubectl apply -f %s%s", fileName, ContextFlag(nil)))
} else {
cmd = exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl apply -f %s%s", fileName, ContextFlag(nil)))
cmd = utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl apply -f %s%s", fileName, ContextFlag(nil)))
}

output, err := cmd.CombinedOutput()
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -104,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe certificate %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe certificate %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/cluster-role-bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -76,7 +75,7 @@ func DeleteK8sClusterRoleBindingBy(name string, contextId *string) error {
}

func DescribeK8sClusterRoleBinding(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe clusterrolebinding %s%s", name, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe clusterrolebinding %s%s", name, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/cluster-roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -79,7 +78,7 @@ func DeleteK8sClusterRoleBy(name string, contextId *string) error {
}

func DescribeK8sClusterRole(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe clusterrole %s%s", name, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe clusterrole %s%s", name, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/clusterIssuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -78,7 +77,7 @@ func DeleteK8sClusterIssuerBy(name string, contextId *string) error {
}

func DescribeK8sClusterIssuer(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe clusterissuer %s%s", name, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe clusterissuer %s%s", name, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -116,7 +115,7 @@ func DeleteK8sConfigmapBy(namespaceName string, name string, contextId *string)
}

func DescribeK8sConfigmap(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe configmap %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe configmap %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kubernetes

import (
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -57,7 +56,7 @@ func DeleteK8sCustomResourceDefinition(data apiExt.CustomResourceDefinition) uti
}

func DescribeK8sCustomResourceDefinition(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe crds %s%s", name, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe crds %s%s", name, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -78,7 +77,7 @@ func DeleteK8sCronJobBy(namespace string, name string, contextId *string) error
}

func DescribeK8sCronJob(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe cronjob %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe cronjob %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -78,7 +77,7 @@ func DeleteK8sCertificateSigningRequestBy(namespace string, name string, context
}

func DescribeK8sCertificateSigningRequest(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe -n %s csr%s", name, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe -n %s csr%s", name, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -99,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe daemonset %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe daemonset %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/deleteResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"
"strings"

"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -83,7 +82,7 @@ func removeIngress(provider *KubeProvider) {
}
if ingressControllerType == TRAEFIK {
fmt.Printf("Deleting TRAEFIK middleware ...\n")
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl delete middleware mw-backend -n %s", utils.CONFIG.Kubernetes.OwnNamespace))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl delete middleware mw-backend -n %s", utils.CONFIG.Kubernetes.OwnNamespace))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -112,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe deployment %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe deployment %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -77,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe endpoint %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe endpoint %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -42,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe event %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe event %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
72 changes: 0 additions & 72 deletions kubernetes/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,14 @@ import (
"fmt"
"io"
"log"
"os/exec"

"github.com/gorilla/websocket"
"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
// corev1 "k8s.io/api/core/v1"
//"k8s.io/client-go/tools/remotecommand"
//"k8s.io/kubectl/pkg/scheme"
)

func ExecTest() error {
namespace := "mogenius"
podName := "mogenius-k8s-manager-6dcf5df696-8bsf4"
container := "mogenius-k8s-manager"
execCmd := []string{"exec", "--stdin", "--tty", "-n", namespace, "--container", container, podName, "--", "ifconfig"} // /bin/sh

// Create an *exec.Cmd
cmd := exec.Command("kubectl", execCmd...)
cmdStdout, _ := cmd.StdoutPipe()
cmdStdin, _ := cmd.StdinPipe()

// Assign os.Stdin, os.Stdout, and os.Stderr
// cmd.Stdin = os.Stdin
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr

go SendData(cmdStdin, cmdStdout)

// Run the command
err := cmd.Run()

if err != nil {
logger.Log.Errorf("ExecTest ERR: %s", err.Error())
}

return err
}

// This method is the equivalent of:
// kubectl exec -n benegeilomat-dev-8umm0v --container nginx nginx-6b64bff7c9-p6vpp -- ls
// func ExecTest() error {
// provider,err := NewKubeProvider()

// namespace := "benegeilomat-dev-8umm0v"
// podName := "nginx-6b64bff7c9-p6vpp"
// container := "nginx"
// cmd := []string{"/bin/bash"} // ls

// req := provider.ClientSet.CoreV1().RESTClient().Post().
// Resource("pods").
// Namespace(namespace).
// Name(podName).
// SubResource("exec").
// VersionedParams(&corev1.PodExecOptions{
// Command: cmd,
// Container: container,
// Stdin: true, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// Stdout: true, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// Stderr: false, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// TTY: true, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// }, scheme.ParameterCodec)

// exec, err := remotecommand.NewSPDYExecutor(&provider.ClientConfig, "POST", req.URL())
// if err != nil {
// logger.Log.Errorf("ExecTest ERR: %s", err.Error())
// }

// err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{
// Stdin: os.Stdin, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// Stdout: os.Stdout, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// Stderr: nil, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// Tty: true, // DO NOT CHANGE: ONLY WORKING CONFIGURATION
// })

// if err != nil {
// logger.Log.Errorf("ExecTest ERR: %s", err.Error())
// }
// return err
// }

func SendData(cmdStdin io.WriteCloser, cmdStdout io.ReadCloser) {
// Create a dialer
dialer := websocket.DefaultDialer
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/utils"

Expand Down Expand Up @@ -78,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe hpa %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe hpa %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -102,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("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe ingress %s -n %s%s", name, namespace, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe ingress %s -n %s%s", name, namespace, ContextFlag(contextId)))

output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/ingressClass.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"context"
"fmt"
"os/exec"

"github.com/mogenius/punq/logger"
"github.com/mogenius/punq/utils"
Expand Down Expand Up @@ -92,7 +91,7 @@ func DeleteK8sIngressClassBy(name string, contextId *string) error {
}

func DescribeK8sIngressClass(name string, contextId *string) utils.K8sWorkloadResult {
cmd := exec.Command("/bin/ash", "-c", fmt.Sprintf("/usr/local/bin/kubectl describe ingressclass %s%s", name, ContextFlag(contextId)))
cmd := utils.RunOnLocalShell(fmt.Sprintf("/usr/local/bin/kubectl describe ingressclass %s%s", name, ContextFlag(contextId)))

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

0 comments on commit 093b000

Please sign in to comment.