diff --git a/.github/actions/e2e/install-karpenter/action.yaml b/.github/actions/e2e/install-karpenter/action.yaml index b6c5f2a2c6f6..4599e2dcca69 100644 --- a/.github/actions/e2e/install-karpenter/action.yaml +++ b/.github/actions/e2e/install-karpenter/action.yaml @@ -22,6 +22,9 @@ inputs: k8s_version: description: 'Version of Kubernetes to use for the launched cluster' default: "1.28" + webhooks_enabled: + description: "Whether webhooks are enabled or not. Valid values are 'true' or 'false'" + default: 'true' git_ref: description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release" runs: @@ -52,13 +55,12 @@ runs: # Parse minor version to determine whether to enable the webhooks VERSION=${{ inputs.k8s_version }} RELEASE_VERSION_MINOR="${VERSION#*.}" - WEBHOOK_ENABLED=true helm upgrade --install karpenter oci://${{ inputs.ecr_account_id }}.dkr.ecr.${{ inputs.ecr_region }}.amazonaws.com/karpenter/snapshot/karpenter \ -n kube-system \ --version "v0-$(git rev-parse HEAD)" \ --set serviceAccount.annotations."eks\.amazonaws\.com/role-arn"="arn:aws:iam::${{ inputs.account_id }}:role/karpenter-irsa-${{ inputs.cluster_name }}" \ - --set webhook.enabled=${WEBHOOK_ENABLED} \ + --set webhook.enabled=${{ inputs.webhooks_enabled }} \ --set settings.clusterName="${{ inputs.cluster_name }}" \ --set settings.interruptionQueue="${{ inputs.cluster_name }}" \ --set controller.resources.requests.cpu=3 \ diff --git a/.github/actions/e2e/setup-cluster/action.yaml b/.github/actions/e2e/setup-cluster/action.yaml index 2bdcd853c282..3ecc45774b81 100644 --- a/.github/actions/e2e/setup-cluster/action.yaml +++ b/.github/actions/e2e/setup-cluster/action.yaml @@ -37,6 +37,9 @@ inputs: private_cluster: description: "Whether to create a private cluster which does not add access to the public internet. Valid values are 'true' or 'false'" default: 'false' + webhooks_enabled: + description: "Whether webhooks are enabled or not. Valid values are 'true' or 'false'" + default: 'true' git_ref: description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release" required: false @@ -216,4 +219,5 @@ runs: ecr_region: ${{ inputs.ecr_region }} cluster_name: ${{ inputs.cluster_name }} k8s_version: ${{ inputs.k8s_version }} + webhooks_enabled: ${{ inputs.webhooks_enabled }} git_ref: ${{ inputs.git_ref }} diff --git a/.github/workflows/e2e-matrix.yaml b/.github/workflows/e2e-matrix.yaml index eff347721721..c693fbec7196 100644 --- a/.github/workflows/e2e-matrix.yaml +++ b/.github/workflows/e2e-matrix.yaml @@ -67,6 +67,7 @@ jobs: - Expiration - Chaos - IPv6 + - Webhooks uses: ./.github/workflows/e2e.yaml with: suite: ${{ matrix.suite }} diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index bbd387d37438..3c8171830ff8 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -26,6 +26,7 @@ on: - IPv6 - Scale - PrivateCluster + - Webhooks k8s_version: type: choice options: @@ -116,6 +117,7 @@ jobs: ecr_region: ${{ vars.ECR_REGION }} prometheus_workspace_id: ${{ vars.WORKSPACE_ID }} prometheus_region: ${{ vars.PROMETHEUS_REGION }} + webhooks_enabled: ${{ inputs.suite != 'Webhooks' && true }} # Set webhooks_enabled to false if running webhook smoke test suite - name: run the ${{ inputs.suite }} test suite run: | TEST_SUITE="${{ inputs.suite }}" diff --git a/test/suites/webhooks/suite_test.go b/test/suites/webhooks/suite_test.go new file mode 100644 index 000000000000..e8e84cd6aa93 --- /dev/null +++ b/test/suites/webhooks/suite_test.go @@ -0,0 +1,66 @@ +/* +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 webhooks_test + +import ( + "context" + "testing" + + v1beta1 "github.com/aws/karpenter/pkg/apis/v1beta1" + "github.com/aws/karpenter/test/pkg/environment/aws" + + karpv1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1" + + karptest "sigs.k8s.io/karpenter/pkg/test" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "knative.dev/pkg/logging/testing" +) + +var ctx context.Context +var env *aws.Environment +var nodeClass *v1beta1.EC2NodeClass +var nodePool *karpv1beta1.NodePool + +func TestWebhooks(t *testing.T) { + RegisterFailHandler(Fail) + + ctx = TestContextWithLogger(t) + BeforeSuite(func() { + env = aws.NewEnvironment(t) + }) + AfterSuite(func() { + env.Stop() + }) + RunSpecs(t, "Webhooks") +} + +var _ = BeforeEach(func() { + env.BeforeEach() + nodeClass = env.DefaultEC2NodeClass() + nodePool = env.DefaultNodePool(nodeClass) +}) +var _ = AfterEach(func() { env.Cleanup() }) +var _ = AfterEach(func() { env.AfterEach() }) + +var _ = Describe("Webhooks", func() { + It("should schedule pods when webhooks are disabled", func() { + pod := karptest.Pod() + env.ExpectCreated(pod, nodeClass, nodePool) + env.EventuallyExpectHealthy(pod) + env.ExpectCreatedNodeCount("==", 1) + }) +})