You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@submarine.apache.org by ka...@apache.org on 2021/07/04 15:03:01 UTC
[submarine] branch master updated: SUBMARINE-892. Remove unused
files in our controller
This is an automated email from the ASF dual-hosted git repository.
kaihsun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push:
new 8d56b9b SUBMARINE-892. Remove unused files in our controller
8d56b9b is described below
commit 8d56b9bc27b9f1041b530c12c887c6e0f822bb93
Author: MortalHappiness <b0...@ntu.edu.tw>
AuthorDate: Sun Jul 4 18:00:06 2021 +0800
SUBMARINE-892. Remove unused files in our controller
### What is this PR for?
Currently `submarine-cloud-v2/main_test.go` is unused since it will be replace by new testing framework. `submarine-cloud-v2/pkg/k8sutil` will no longer be used since we will use NodePort service instead of port forwarding in production environment. Therefore these two files can be deleted.
### What type of PR is it?
[Refactoring]
### Todos
### What is the Jira issue?
https://issues.apache.org/jira/browse/SUBMARINE-892
### How should this be tested?
### Screenshots (if appropriate)
### Questions:
* Do the license files need updating? No
* Are there breaking changes for older versions? No
* Does this need new documentation? No
Author: MortalHappiness <b0...@ntu.edu.tw>
Signed-off-by: Kai-Hsun Chen <ka...@apache.org>
Closes #644 from MortalHappiness/SUBMARINE-892 and squashes the following commits:
10bf9963 [MortalHappiness] SUBMARINE-892. Remove unused files in our controller
---
submarine-cloud-v2/main_test.go | 68 -------------------
submarine-cloud-v2/pkg/k8sutil/portfwd.go | 107 ------------------------------
2 files changed, 175 deletions(-)
diff --git a/submarine-cloud-v2/main_test.go b/submarine-cloud-v2/main_test.go
deleted file mode 100644
index 0956457..0000000
--- a/submarine-cloud-v2/main_test.go
+++ /dev/null
@@ -1,68 +0,0 @@
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 main
-
-import (
- "context"
- "submarine-cloud-v2/pkg/generated/clientset/versioned/typed/submarine/v1alpha1"
- "fmt"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/client-go/tools/clientcmd"
- "k8s.io/client-go/kubernetes"
- "testing"
- "reflect"
-)
-
-
-var (
- namespace = "default"
-)
-
-func TestSubmarineClient(t *testing.T) {
- ctx := context.Background()
- config, e := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
- if e != nil {
- panic(e.Error())
- }
- client, e := v1alpha1.NewForConfig(config)
- if e != nil {
- panic(e.Error())
- }
-
- submarineList, e := client.Submarines(namespace).List(ctx, metav1.ListOptions{})
- if e != nil {
- panic(e.Error())
- }
- fmt.Println(reflect.TypeOf(submarineList), e)
- // fmt.Println(submarineList, e)
-}
-
-func TestK8sClient(t *testing.T) {
- ctx := context.Background()
- config, e := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
- if e != nil {
- panic(e.Error())
- }
- client, e := kubernetes.NewForConfig(config)
- if e != nil {
- panic(e.Error())
- }
- PodsList, e := client.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
- fmt.Println(reflect.TypeOf(PodsList), e)
- // fmt.Println(PodsList, e)
-}
diff --git a/submarine-cloud-v2/pkg/k8sutil/portfwd.go b/submarine-cloud-v2/pkg/k8sutil/portfwd.go
deleted file mode 100644
index 98ff136..0000000
--- a/submarine-cloud-v2/pkg/k8sutil/portfwd.go
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-// Reference: https://github.com/minio/operator/blob/master/kubectl-minio/cmd/proxy.go#L131
-
-package k8sutil
-
-import (
- "context"
- "fmt"
- "github.com/fatih/color"
- "io"
- "log"
- "os/exec"
- "strconv"
- "sync"
-)
-
-// run the command inside a goroutine, return a channel that closes then the command dies
-func ServicePortForwardPort(ctx context.Context, namespace string, service string, localPort int, remotePort int, dcolor color.Attribute) *exec.Cmd {
- // service we are going to forward
- serviceName := fmt.Sprintf("service/%s", service)
- // command to run
- portStr := strconv.Itoa(localPort) + ":" + strconv.Itoa(remotePort)
- cmd := exec.CommandContext(ctx, "kubectl", "port-forward", "--address", "0.0.0.0", "-n", namespace, serviceName, portStr)
-
- go func(cmd *exec.Cmd) {
- // prepare to capture the output
- var errStdout, errStderr error
- stdoutIn, _ := cmd.StdoutPipe()
- stderrIn, _ := cmd.StderrPipe()
- err := cmd.Start()
- if err != nil {
- log.Fatalf("cmd.Start() failed with '%s'\n", err)
- }
-
- // cmd.Wait() should be called only after we finish reading
- // from stdoutIn and stderrIn.
- // wg ensures that we finish
- var wg sync.WaitGroup
- wg.Add(1)
- go func() {
- errStdout = copyAndCapture(stdoutIn, dcolor)
- wg.Done()
- }()
-
- errStderr = copyAndCapture(stderrIn, dcolor)
-
- wg.Wait()
-
- err = cmd.Wait()
- if err != nil {
- if err.Error() == "signal: killed" {
- log.Printf("Stop port-forward\n")
- } else {
- log.Printf("cmd.Run() failed with %s\n", err.Error())
- }
- return
- }
- if errStdout != nil || errStderr != nil {
- log.Printf("failed to capture stdout or stderr\n")
- return
- }
- }(cmd)
-
- return cmd
-}
-
-// capture and print the output of the command
-func copyAndCapture(r io.Reader, dcolor color.Attribute) error {
- var out []byte
- buf := make([]byte, 1024)
- for {
- n, err := r.Read(buf[:])
- if n > 0 {
- d := buf[:n]
- out = append(out, d...)
- theColor := color.New(dcolor)
- _, err := theColor.Print(string(d))
-
- if err != nil {
- return err
- }
- }
- if err != nil {
- // Read returns io.EOF at the end of file, which is not an error for us
- if err == io.EOF {
- err = nil
- }
- return err
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@submarine.apache.org
For additional commands, e-mail: dev-help@submarine.apache.org