Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing port when default configuration is selected. #21

Merged
merged 1 commit into from
Sep 12, 2022
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
8 changes: 1 addition & 7 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func isJSONString(s string) bool {
return json.Unmarshal([]byte(s), &js) == nil
}

func CheckForEmptyArgsAndExit(args []string, message string){
func CheckForEmptyArgsAndExit(args []string, message string) {
if len(args) == 0 {
fmt.Println(message)
os.Exit(1)
Expand Down Expand Up @@ -53,18 +53,12 @@ func PrintPods(podList v1.PodList) {
}

func PrintPrettyHttpResponse(resp *http.Response, err error) {
if err != nil {
fmt.Printf("[*] Failed to run HTTP request with error: %s\n", err)
os.Exit(1)
}

bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

bodyString := string(bodyBytes)

if resp.StatusCode == http.StatusOK {

// TODO: consider changing it by checking the first and the last byte "{..}".
Expand Down
8 changes: 3 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"github.com/spf13/cobra"
"io/ioutil"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"kubeletctl/pkg/api"
"log"
"net/url"
restclient "k8s.io/client-go/rest"
"os"
)

Expand Down Expand Up @@ -164,7 +164,8 @@ func initConfig() {
&clientcmd.ConfigOverrides{},
)
config, err = kubeConfig.ClientConfig()
if err != nil && len(os.Getenv(clientcmd.RecommendedConfigPathEnvVar)) > 0 {
// TODO: should fail when YAML is wrong, like with ":"
if err != nil { //&& len(os.Getenv(clientcmd.RecommendedConfigPathEnvVar)) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added a comment as part of your checks, I will fix it

fmt.Fprintln(os.Stderr, "[*] There is a problem with the file in KUBECONFIG environment variable\n[*] You can ignore it by modifying the KUBECONFIG environment variable, file \"~/.kube/config\" or use the \"-i\" switch")
panic(err.Error())
}
Expand All @@ -176,9 +177,6 @@ func initConfig() {
if err != nil {
panic(err.Error())
}
if PortFlag == "" {
PortFlag = hostUrl.Port()
}
if ServerIpAddressFlag == "" {
ServerIpAddressFlag = hostUrl.Hostname()
}
Expand Down