Skip to content

Commit

Permalink
feat: support multiple externalIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipme committed Oct 21, 2024
1 parent c166410 commit f9fecbb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/interfaces/nodeinfo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package interfaces

type NodeInfo struct {
Name string
InternalIP string
ExternalIP string
Name string
InternalIP string
ExternalIPs []string
}
10 changes: 5 additions & 5 deletions internal/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ func (s *KubeService) GetNodeInfo(ctx context.Context) ([]*interfaces.NodeInfo,
var nodeList []*interfaces.NodeInfo
for _, node := range nodes.Items {
var internalIP string
var externalIP string
var externalIPs []string
for _, address := range node.Status.Addresses {
switch address.Type {
case v1.NodeInternalIP:
internalIP = address.Address
case v1.NodeExternalIP:
externalIP = address.Address
externalIPs = append(externalIPs, address.Address)
}
}
if internalIP != "" {
nodeList = append(nodeList, &interfaces.NodeInfo{
Name: node.Name,
InternalIP: internalIP,
ExternalIP: externalIP,
Name: node.Name,
InternalIP: internalIP,
ExternalIPs: externalIPs,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/s3policy/s3policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewS3PolicyHelper(helperConfig *S3PolicyHelperConfig) (*S3PolicyHelper, err
func (h *S3PolicyHelper) ClusterNodesUpdated(ctx context.Context, nodes []*interfaces.NodeInfo) error {
var ips []string
for _, node := range nodes {
ips = append(ips, node.ExternalIP)
ips = append(ips, node.ExternalIPs...)
}
configData := configData{
BucketName: h.bucket,
Expand Down
25 changes: 25 additions & 0 deletions internal/s3policy/s3policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package s3policy

import (
"html/template"
"strings"
"testing"
)

func TestBucketPolicyTemplate(t *testing.T) {
tem := template.Must(template.New("bucketPolicy").Funcs(template.FuncMap{
"sub": sub,
}).Parse(bucketPolicyTemplate))

configData := configData{
BucketName: "hello",
IPs: []string{"127.0.0.1", "127.0.0.2"},
}

var policyOutput strings.Builder
if err := tem.Execute(&policyOutput, configData); err != nil {
t.Errorf("Failed to execute template: %v", err)
}

t.Log(policyOutput.String())
}

0 comments on commit f9fecbb

Please sign in to comment.