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

bugfix: exec k8s config as input #6196

Merged
merged 1 commit into from
Dec 21, 2023
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
6 changes: 3 additions & 3 deletions pkg/lorry/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package client

import (
context "context"
"context"
"errors"
"net/http"

Expand Down Expand Up @@ -53,12 +53,12 @@ func NewClient(pod corev1.Pod) (Client, error) {
return mockClient, mockClientError
}

_, err := rest.InClusterConfig()
config, err := rest.InClusterConfig()
if err != nil {
// As the service does not run as a pod in the Kubernetes cluster,
// it is unable to call the lorry service running as a pod using the pod's IP address.
// In this scenario, it is recommended to use an k8s exec client instead.
execClient, err := NewK8sExecClientWithPod(&pod)
execClient, err := NewK8sExecClientWithPod(config, &pod)
if err != nil {
return nil, err
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/lorry/client/k8sexec_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package client

import (
"bytes"
context "context"
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -56,7 +56,7 @@ type K8sExecClient struct {
}

// NewK8sExecClientWithPod create a new OperationHTTPClient with lorry container
func NewK8sExecClientWithPod(pod *corev1.Pod) (*K8sExecClient, error) {
func NewK8sExecClientWithPod(restConfig *rest.Config, pod *corev1.Pod) (*K8sExecClient, error) {
var (
err error
)
Expand All @@ -82,11 +82,6 @@ func NewK8sExecClientWithPod(pod *corev1.Pod) (*K8sExecClient, error) {
Namespace: pod.Namespace,
}

restConfig, err := ctrl.GetConfig()
if err != nil {
return nil, errors.Wrap(err, "get k8s config failed")
}

restConfig.GroupVersion = &schema.GroupVersion{Group: "", Version: "v1"}
restConfig.APIPath = "/api"
restConfig.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
Expand Down
Loading