-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update log level and add integration test to verify deleteENI permission
- Loading branch information
Showing
4 changed files
with
143 additions
and
1 deletion.
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,46 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 ec2api_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/config" | ||
"github.com/aws/amazon-vpc-resource-controller-k8s/test/framework" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestEc2api(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "EC2API Suite") | ||
} | ||
|
||
var frameWork *framework.Framework | ||
var nodeListLen int | ||
var _ = BeforeSuite(func() { | ||
By("creating a framework") | ||
frameWork = framework.New(framework.GlobalOptions) | ||
By("verify node count before test") | ||
nodeList, err := frameWork.NodeManager.GetNodesWithOS(config.OSLinux) | ||
Expect(err).ToNot(HaveOccurred()) | ||
nodeListLen = len(nodeList.Items) | ||
Expect(nodeListLen).To(BeNumerically(">", 1)) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
nodeList, err := frameWork.NodeManager.GetNodesWithOS(config.OSLinux) | ||
Expect(err).ToNot(HaveOccurred()) | ||
By("verifying node count after test is unchanged") | ||
Expect(len(nodeList.Items)).To(Equal(nodeListLen)) | ||
}) |
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,48 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 ec2api_test | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/config" | ||
"github.com/aws/amazon-vpc-resource-controller-k8s/test/framework/utils" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = FDescribe("Test IAM permissions for EC2 API calls", func() { | ||
Describe("[LOCAL]Test DeleteNetworkInterface permission", func() { | ||
Context("when instance is terminated", func() { | ||
It("it should only delete ENIs provisioned by the controller or vpc-cni", func() { | ||
nodeList, err := frameWork.NodeManager.GetNodesWithOS(config.OSLinux) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(nodeList.Items).ToNot(BeEmpty()) | ||
instanceID := frameWork.NodeManager.GetInstanceID(&nodeList.Items[0]) | ||
By("creating test ENI without eks:eni:owner tag and attach to EC2 instance") | ||
nwInterfaceID, err := frameWork.EC2Manager.CreateAndAttachNetworkInterface(instanceID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
By("terminating the instance and sleeping") | ||
err = frameWork.EC2Manager.TerminateInstances(instanceID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
// allow time for instance to be deleted and ENI to be available, new node to be ready | ||
time.Sleep(utils.ResourceCreationTimeout) | ||
By("verifying ENI exists and delete test ENI") | ||
err = frameWork.EC2Manager.DescribeNetworkInterface(nwInterfaceID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
err = frameWork.EC2Manager.DeleteNetworkInterface(nwInterfaceID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
}) |