-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publish instanceType, capacityType, availabilityZone in a k8s e…
…vent when we receive a IsUnfulfillableCapacity error while trying to create fleet (#3999) Co-authored-by: Jonathan Innis <joinnis@amazon.com>
- Loading branch information
1 parent
49642f0
commit 82f68a5
Showing
7 changed files
with
179 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 cache | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
|
||
"github.com/aws/karpenter-core/pkg/events" | ||
) | ||
|
||
func UnavailableOfferingEvent(instanceType, availabilityZone, capacityType string) events.Event { | ||
return events.Event{ | ||
Type: v1.EventTypeWarning, | ||
Reason: "UnavailableOffering", | ||
Message: fmt.Sprintf(`UnavailableOffering for {"instanceType": %q, "availabilityZone": %q, "capacityType": %q}`, instanceType, availabilityZone, capacityType), | ||
DedupeValues: []string{instanceType, availabilityZone, capacityType}, | ||
} | ||
} |
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,33 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 cache_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "knative.dev/pkg/logging/testing" | ||
_ "knative.dev/pkg/system/testing" | ||
) | ||
|
||
var ctx context.Context | ||
|
||
func TestAPIs(t *testing.T) { | ||
ctx = TestContextWithLogger(t) | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Cache") | ||
} |
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,97 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 cache_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
_ "knative.dev/pkg/system/testing" | ||
|
||
"github.com/aws/karpenter-core/pkg/apis/v1alpha5" | ||
"github.com/aws/karpenter-core/pkg/test" | ||
"github.com/aws/karpenter/pkg/cache" | ||
) | ||
|
||
var unavailableOfferingsCache *cache.UnavailableOfferings | ||
var recorder *test.EventRecorder | ||
|
||
var _ = Describe("UnavailableOfferings", func() { | ||
BeforeEach(func() { | ||
ctx = context.Background() | ||
recorder = test.NewEventRecorder() | ||
unavailableOfferingsCache = cache.NewUnavailableOfferings(recorder) | ||
}) | ||
|
||
AfterEach(func() { | ||
recorder.Reset() | ||
}) | ||
|
||
It("should create an UnavailableOfferingEvent when receiving a CreateFleet error", func() { | ||
unavailableOfferingsCache.MarkUnavailableForFleetErr(ctx, &ec2.CreateFleetError{ | ||
LaunchTemplateAndOverrides: &ec2.LaunchTemplateAndOverridesResponse{ | ||
Overrides: &ec2.FleetLaunchTemplateOverrides{ | ||
InstanceType: aws.String("c5.large"), | ||
AvailabilityZone: aws.String("test-zone-1a"), | ||
}, | ||
}, | ||
}, v1alpha5.CapacityTypeSpot) | ||
Expect(recorder.Calls("UnavailableOffering")).To(BeNumerically("==", 1)) | ||
Expect(recorder.DetectedEvent(`UnavailableOffering for {"instanceType": "c5.large", "availabilityZone": "test-zone-1a", "capacityType": "spot"}`)) | ||
}) | ||
It("should create an UnavailableOfferingEvent when marking an offering as unavailable", func() { | ||
unavailableOfferingsCache.MarkUnavailable(ctx, "offering is unavailable", "c5.large", "test-zone-1a", v1alpha5.CapacityTypeSpot) | ||
Expect(recorder.Calls("UnavailableOffering")).To(BeNumerically("==", 1)) | ||
Expect(recorder.DetectedEvent(`UnavailableOffering for {"instanceType": "c5.large", "availabilityZone": "test-zone-1a", "capacityType": "spot"}`)) | ||
}) | ||
It("should create multiple UnavailableOfferingEvent when marking multiple offerings as unavailable", func() { | ||
type offering struct { | ||
instanceType string | ||
availabilityZone string | ||
capacityType string | ||
} | ||
|
||
offerings := []offering{ | ||
{ | ||
instanceType: "c5.large", | ||
availabilityZone: "test-zone-1a", | ||
capacityType: v1alpha5.CapacityTypeSpot, | ||
}, | ||
{ | ||
instanceType: "g4dn.xlarge", | ||
availabilityZone: "test-zone-1b", | ||
capacityType: v1alpha5.CapacityTypeOnDemand, | ||
}, | ||
{ | ||
instanceType: "inf1.24xlarge", | ||
availabilityZone: "test-zone-1d", | ||
capacityType: v1alpha5.CapacityTypeSpot, | ||
}, | ||
{ | ||
instanceType: "t3.nano", | ||
availabilityZone: "test-zone-1b", | ||
capacityType: v1alpha5.CapacityTypeOnDemand, | ||
}, | ||
} | ||
|
||
for _, of := range offerings { | ||
unavailableOfferingsCache.MarkUnavailable(ctx, "offering is unavailable", of.instanceType, of.availabilityZone, of.capacityType) | ||
} | ||
Expect(recorder.Calls("UnavailableOffering")).To(BeNumerically("==", len(offerings))) | ||
}) | ||
}) |
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