Skip to content

Commit e4df63a

Browse files
committed
test: save original aws resource quotas as returned by API
Signed-off-by: Richard Case <[email protected]>
1 parent 36938d5 commit e4df63a

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
@@ -798,24 +798,27 @@ type ServiceQuota struct {
798798
RequestStatus string
799799
}
800800

801-
func EnsureServiceQuotas(sess client.ConfigProvider) map[string]*ServiceQuota {
801+
func EnsureServiceQuotas(sess client.ConfigProvider) (map[string]*ServiceQuota, map[string]*servicequotas.ServiceQuota) {
802802
limitedResources := getLimitedResources()
803803
serviceQuotasClient := servicequotas.New(sess)
804804

805+
originalQuotas := map[string]*servicequotas.ServiceQuota{}
806+
805807
for k, v := range limitedResources {
806808
out, err := serviceQuotasClient.GetServiceQuota(&servicequotas.GetServiceQuotaInput{
807809
QuotaCode: aws.String(v.QuotaCode),
808810
ServiceCode: aws.String(v.ServiceCode),
809811
})
810812
Expect(err).NotTo(HaveOccurred())
813+
originalQuotas[k] = out.Quota
811814
v.Value = int(aws.Float64Value(out.Quota.Value))
812815
limitedResources[k] = v
813816
if v.Value < v.DesiredMinimumValue {
814817
v.attemptRaiseServiceQuotaRequest(serviceQuotasClient)
815818
}
816819
}
817820

818-
return limitedResources
821+
return limitedResources, originalQuotas
819822
}
820823

821824
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)