-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1149 from weaveworks/toggle-public-private-endpoi…
…nt-access Enable management of access to public/private API endpoints
- Loading branch information
Showing
26 changed files
with
906 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// +build integration | ||
|
||
package integration_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
awseks "github.com/aws/aws-sdk-go/service/eks" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
|
||
. "github.com/weaveworks/eksctl/integration/matchers" | ||
. "github.com/weaveworks/eksctl/integration/runner" | ||
|
||
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils" | ||
|
||
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" | ||
) | ||
|
||
const ( | ||
createCluster = `Create` | ||
updateCluster = `Update` | ||
deleteCluster = `Delete` | ||
endpointPubTmpl = `EndpointPublicAccess: %v` | ||
endpointPrivTmpl = `EndpointPrivateAccess: %v` | ||
) | ||
|
||
func setEndpointConfig(cfg *api.ClusterConfig, privateAccess, publicAccess bool) { | ||
cfg.VPC.ClusterEndpoints.PrivateAccess = &privateAccess | ||
cfg.VPC.ClusterEndpoints.PublicAccess = &publicAccess | ||
} | ||
|
||
func generateName(prefix string) string { | ||
if clusterName == "" { | ||
clusterName = cmdutils.ClusterName("", "") | ||
} | ||
return fmt.Sprintf("%v-%v", prefix, clusterName) | ||
} | ||
|
||
func setMetadata(cfg *api.ClusterConfig, name, region string) { | ||
cfg.Metadata.Name = name | ||
cfg.Metadata.Region = region | ||
} | ||
|
||
var _ = Describe("(Integration) Create and Update Cluster with Endpoint Configs", func() { | ||
|
||
type endpointAccessCase struct { | ||
Name string | ||
Private bool | ||
Public bool | ||
Type string | ||
Fails bool | ||
} | ||
|
||
DescribeTable("Can create/update Cluster Endpoint Access", | ||
func(e endpointAccessCase) { | ||
//create clusterconfig | ||
cfg := api.NewClusterConfig() | ||
clName := generateName(e.Name) | ||
setEndpointConfig(cfg, e.Private, e.Public) | ||
setMetadata(cfg, clName, region) | ||
|
||
// create and populate config file from clusterconfig | ||
bytes, err := json.Marshal(cfg) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(len(bytes)).ToNot(BeZero()) | ||
tmpfile, err := ioutil.TempFile("", "clusterendpointtests") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
defer os.Remove(tmpfile.Name()) | ||
|
||
_, err = tmpfile.Write(bytes) | ||
Expect(err).ToNot(HaveOccurred()) | ||
err = tmpfile.Close() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// create cluster with config file | ||
if e.Type == createCluster { | ||
cmd := eksctlCreateCmd.WithArgs( | ||
"cluster", | ||
"--verbose", "2", | ||
"--config-file", tmpfile.Name(), | ||
"--without-nodegroup", | ||
).WithoutArg("--region", region) | ||
if e.Fails { | ||
Expect(cmd).ShouldNot(RunSuccessfully()) | ||
return | ||
} | ||
Expect(cmd).Should(RunSuccessfully()) | ||
awsSession := NewSession(region) | ||
Eventually(awsSession, timeOut, pollInterval).Should( | ||
HaveExistingCluster(clName, awseks.ClusterStatusActive, version)) | ||
} else if e.Type == updateCluster { | ||
utilsCmd := eksctlUtilsCmd.WithArgs( | ||
"update-cluster-endpoints", | ||
"--name", clName, | ||
fmt.Sprintf("--private-access=%v", e.Private), | ||
fmt.Sprintf("--public-access=%v", e.Public), | ||
"--approve") | ||
if e.Fails { | ||
Expect(utilsCmd).ShouldNot(RunSuccessfully()) | ||
return | ||
} | ||
Expect(utilsCmd).Should(RunSuccessfully()) | ||
} | ||
getCmd := eksctlGetCmd.WithArgs( | ||
"cluster", | ||
"--name", clName, | ||
"-o", "yaml", | ||
) | ||
Expect(getCmd).To(RunSuccessfullyWithOutputStringLines( | ||
ContainElement(ContainSubstring(endpointPubTmpl, e.Public)), | ||
ContainElement(ContainSubstring(endpointPrivTmpl, e.Private)), | ||
)) | ||
if e.Type == deleteCluster { | ||
// nned to update public access to allow access to delete when it isn't allowed | ||
if e.Public == false { | ||
utilsCmd := eksctlUtilsCmd.WithArgs( | ||
"update-cluster-endpoints", | ||
"--name", clName, | ||
fmt.Sprintf("--public-access=%v", true), | ||
fmt.Sprintf("--approve"), | ||
) | ||
Expect(utilsCmd).Should(RunSuccessfully()) | ||
} | ||
deleteCmd := eksctlDeleteCmd.WithArgs( | ||
"cluster", | ||
"--name", clName, | ||
) | ||
Expect(deleteCmd).Should(RunSuccessfully()) | ||
awsSession := NewSession(region) | ||
Eventually(awsSession, timeOut, pollInterval). | ||
ShouldNot(HaveExistingCluster(clName, awseks.ClusterStatusActive, version)) | ||
} | ||
}, | ||
Entry("Create cluster1, Private=false, Public=true, should succeed", endpointAccessCase{ | ||
Name: "cluster1", | ||
Private: false, | ||
Public: true, | ||
Type: createCluster, | ||
Fails: false, | ||
}), | ||
Entry("Create cluster2, Private=true, Public=false, should not succeed", endpointAccessCase{ | ||
Name: "cluster2", | ||
Private: true, | ||
Public: false, | ||
Type: createCluster, | ||
Fails: true, | ||
}), | ||
Entry("Create cluster3, Private=true, Public=true, should succeed", endpointAccessCase{ | ||
Name: "cluster3", | ||
Private: true, | ||
Public: true, | ||
Type: createCluster, | ||
Fails: false, | ||
}), | ||
Entry("Create cluster4, Private=false, Public=false, should not succeed", endpointAccessCase{ | ||
Name: "cluster4", | ||
Private: false, | ||
Public: false, | ||
Type: createCluster, | ||
Fails: true, | ||
}), | ||
Entry("Update cluster1 to Private=true, Public=false, should succeed", endpointAccessCase{ | ||
Name: "cluster1", | ||
Private: true, | ||
Public: false, | ||
Type: updateCluster, | ||
Fails: false, | ||
}), | ||
Entry("Update cluster3 to Private=true, Public=false, should succeed", endpointAccessCase{ | ||
Name: "cluster3", | ||
Private: true, | ||
Public: false, | ||
Type: updateCluster, | ||
Fails: false, | ||
}), | ||
Entry("Update cluster3 to Private=false, Public=false, should not succeed", endpointAccessCase{ | ||
Name: "cluster3", | ||
Private: false, | ||
Public: false, | ||
Type: updateCluster, | ||
Fails: true, | ||
}), | ||
Entry("Update cluster3 to Private=false, Public=true, should succeed", endpointAccessCase{ | ||
Name: "cluster3", | ||
Private: false, | ||
Public: true, | ||
Type: updateCluster, | ||
Fails: false, | ||
}), | ||
Entry("Delete cluster1, should succeed (test case updates access)", endpointAccessCase{ | ||
Name: "cluster1", | ||
Private: true, | ||
Public: false, | ||
Type: deleteCluster, | ||
Fails: false, | ||
}), | ||
Entry("Delete cluster3, succeed", endpointAccessCase{ | ||
Name: "cluster3", | ||
Private: false, | ||
Public: true, | ||
Type: deleteCluster, | ||
Fails: false, | ||
}), | ||
) | ||
}) |
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
Oops, something went wrong.