-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use socket to do IPC request to kube-explorer
- Loading branch information
1 parent
99f81b4
commit 66d8b5a
Showing
11 changed files
with
179 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build unix | ||
// +build unix | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"net/url" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
socketFileName = "socket.sock" | ||
) | ||
|
||
func GetSocketName(clusterID string) string { | ||
return fmt.Sprintf("unix://%s", filepath.Join(GetClusterContextPath(clusterID), socketFileName)) | ||
} | ||
|
||
func GetSocketDialer() func(context.Context, string, string) (net.Conn, error) { | ||
return func(ctx context.Context, _, addr string) (net.Conn, error) { | ||
clusterID, _, _ := net.SplitHostPort(addr) | ||
u, _ := url.Parse(GetSocketName(clusterID)) | ||
var d net.Dialer | ||
return d.DialContext(ctx, "unix", u.Path) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
"crypto/md5" | ||
"encoding/hex" | ||
"fmt" | ||
"net" | ||
"net/url" | ||
|
||
"github.com/Microsoft/go-winio" | ||
) | ||
|
||
func GetSocketName(clusterID string) string { | ||
return fmt.Sprintf("namedpipe:/\\.\\pipe\\autok3s-%s", md5hash(clusterID)) | ||
} | ||
|
||
func GetSocketDialer() func(context.Context, string, string) (net.Conn, error) { | ||
return func(ctx context.Context, _, addr string) (net.Conn, error) { | ||
clusterID, _, _ := net.SplitHostPort(addr) | ||
u, _ := url.Parse(GetSocketName(clusterID)) | ||
return winio.DialPipeContext(ctx, u.Path) | ||
} | ||
} | ||
|
||
func md5hash(s string) string { | ||
hash := md5.Sum([]byte(s)) | ||
hexStr := hex.EncodeToString(hash[:]) | ||
return hexStr[:16] | ||
} |
Oops, something went wrong.