Skip to content

Commit 6fef355

Browse files
authored
Merge pull request #3897 from richardcase/resource-quotas-save
test: save original aws resource quotas as returned by API
2 parents c5fddf0 + e4df63a commit 6fef355

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

test/e2e/shared/aws.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,24 +787,27 @@ type ServiceQuota struct {
787787
RequestStatus string
788788
}
789789

790-
func EnsureServiceQuotas(sess client.ConfigProvider) map[string]*ServiceQuota {
790+
func EnsureServiceQuotas(sess client.ConfigProvider) (map[string]*ServiceQuota, map[string]*servicequotas.ServiceQuota) {
791791
limitedResources := getLimitedResources()
792792
serviceQuotasClient := servicequotas.New(sess)
793793

794+
originalQuotas := map[string]*servicequotas.ServiceQuota{}
795+
794796
for k, v := range limitedResources {
795797
out, err := serviceQuotasClient.GetServiceQuota(&servicequotas.GetServiceQuotaInput{
796798
QuotaCode: aws.String(v.QuotaCode),
797799
ServiceCode: aws.String(v.ServiceCode),
798800
})
799801
Expect(err).NotTo(HaveOccurred())
802+
originalQuotas[k] = out.Quota
800803
v.Value = int(aws.Float64Value(out.Quota.Value))
801804
limitedResources[k] = v
802805
if v.Value < v.DesiredMinimumValue {
803806
v.attemptRaiseServiceQuotaRequest(serviceQuotasClient)
804807
}
805808
}
806809

807-
return limitedResources
810+
return limitedResources, originalQuotas
808811
}
809812

810813
func (s *ServiceQuota) attemptRaiseServiceQuotaRequest(serviceQuotasClient *servicequotas.ServiceQuotas) {

test/e2e/shared/resource.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"path/filepath"
2828
"time"
2929

30+
"github.com/aws/aws-sdk-go/service/servicequotas"
3031
"github.com/gofrs/flock"
3132
. "github.com/onsi/gomega"
3233
"sigs.k8s.io/yaml"
@@ -66,6 +67,19 @@ func WriteResourceQuotesToFile(logPath string, serviceQuotas map[string]*Service
6667
Expect(err).NotTo(HaveOccurred())
6768
}
6869

70+
func WriteAWSResourceQuotesToFile(logPath string, serviceQuotas map[string]*servicequotas.ServiceQuota) {
71+
if _, err := os.Stat(logPath); err == nil {
72+
// If resource-quotas file exists, remove it. Should not fail on error, another ginkgo node might have already deleted it.
73+
os.Remove(logPath)
74+
}
75+
76+
data, err := yaml.Marshal(serviceQuotas)
77+
Expect(err).NotTo(HaveOccurred())
78+
79+
err = os.WriteFile(logPath, data, 0644) //nolint:gosec
80+
Expect(err).NotTo(HaveOccurred())
81+
}
82+
6983
func (r *TestResource) String() string {
7084
return fmt.Sprintf("{ec2-normal:%v, vpc:%v, eip:%v, ngw:%v, igw:%v, classiclb:%v, ec2-GPU:%v, volume-gp2:%v}", r.EC2Normal, r.VPC, r.EIP, r.NGW, r.IGW, r.ClassicLB, r.EC2GPU, r.VolumeGP2)
7185
}

test/e2e/shared/suite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte {
158158

159159
if !e2eCtx.Settings.SkipQuotas {
160160
By("Writing AWS service quotas to a file for parallel tests")
161-
quotas := EnsureServiceQuotas(e2eCtx.BootstrapUserAWSSession)
161+
quotas, originalQuotas := EnsureServiceQuotas(e2eCtx.BootstrapUserAWSSession)
162162
WriteResourceQuotesToFile(ResourceQuotaFilePath, quotas)
163163
WriteResourceQuotesToFile(path.Join(e2eCtx.Settings.ArtifactFolder, "initial-resource-quotas.yaml"), quotas)
164+
WriteAWSResourceQuotesToFile(path.Join(e2eCtx.Settings.ArtifactFolder, "initial-aws-resource-quotas.yaml"), originalQuotas)
164165
}
165166

166167
e2eCtx.Settings.InstanceVCPU, err = strconv.Atoi(e2eCtx.E2EConfig.GetVariable(InstanceVcpu))

0 commit comments

Comments
 (0)