Skip to content

Commit

Permalink
Use new infrastructure
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer committed Nov 8, 2022
1 parent 710acf6 commit 18d207a
Show file tree
Hide file tree
Showing 48 changed files with 253 additions and 389 deletions.
51 changes: 4 additions & 47 deletions .github/workflows/pr-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,55 +122,17 @@ jobs:
run: |
gh pr checkout ${{ needs.triage.outputs.pr_num }}
- uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}

- name: Run end to end tests
continue-on-error: true
id: test
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_RUN_IDENTITY_TESTS: true
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
AZURE_APP_INSIGHTS_APP_ID: ${{ secrets.AZURE_APP_INSIGHTS_APP_ID }}
AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
AZURE_APP_INSIGHTS_INSTRUMENTATION_KEY: ${{ secrets.AZURE_APP_INSIGHTS_INSTRUMENTATION_KEY }}
AZURE_DATA_EXPLORER_DB: ${{ secrets.AZURE_DATA_EXPLORER_DB }}
AZURE_DATA_EXPLORER_ENDPOINT: ${{ secrets.AZURE_DATA_EXPLORER_ENDPOINT }}
AZURE_DEVOPS_BUILD_DEFINITION_ID: ${{ secrets.AZURE_DEVOPS_BUILD_DEFINITION_ID }}
AZURE_DEVOPS_ORGANIZATION_URL: ${{ secrets.AZURE_DEVOPS_ORGANIZATION_URL }}
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
AZURE_DEVOPS_POOL_NAME: ${{ secrets.AZURE_DEVOPS_POOL_NAME }}
AZURE_DEVOPS_PROJECT: ${{ secrets.AZURE_DEVOPS_PROJECT }}
AZURE_EVENTHBUS_MANAGEMENT_CONNECTION_STRING : ${{ secrets.AZURE_EVENTHBUS_MANAGEMENT_CONNECTION_STRING }}
AZURE_KEYVAULT_URI: ${{ secrets.AZURE_KEYVAULT_URI }}
AZURE_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.AZURE_LOG_ANALYTICS_WORKSPACE_ID }}
AZURE_RUN_WORKLOAD_IDENTITY_TESTS: true
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_SERVICE_BUS_CONNECTION_STRING: ${{ secrets.AZURE_SERVICE_BUS_CONNECTION_STRING }}
AZURE_SERVICE_BUS_ALTERNATIVE_CONNECTION_STRING: ${{ secrets.AZURE_SERVICE_BUS_ALTERNATIVE_CONNECTION_STRING }}
AZURE_SP_APP_ID: ${{ secrets.AZURE_SP_APP_ID }}
AZURE_SP_OBJECT_ID: ${{ secrets.AZURE_SP_OBJECT_ID }}
AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }}
AZURE_SP_ALTERNATIVE_APP_ID: ${{ secrets.AZURE_SP_ALTERNATIVE_APP_ID }}
AZURE_SP_ALTERNATIVE_OBJECT_ID: ${{ secrets.AZURE_SP_ALTERNATIVE_OBJECT_ID }}
AZURE_SP_ALTERNATIVE_KEY: ${{ secrets.AZURE_SP_ALTERNATIVE_KEY }}
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }}
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY}}
DATADOG_APP_KEY: ${{ secrets.DATADOG_APP_KEY}}
DATADOG_SITE: ${{ secrets.DATADOG_SITE}}
E2E_IMAGE_TAG: ${{ needs.triage.outputs.image_tag }}
GCP_SP_KEY: ${{ secrets.GCP_SP_KEY }}
NEWRELIC_ACCOUNT_ID: ${{ secrets.NEWRELIC_ACCOUNT_ID}}
NEWRELIC_API_KEY: ${{ secrets.NEWRELIC_API_KEY}}
NEWRELIC_LICENSE: ${{ secrets.NEWRELIC_LICENSE}}
OIDC_ISSUER_URL: ${{ secrets.OIDC_ISSUER_URLPR }}
OPENSTACK_AUTH_URL: ${{ secrets.OPENSTACK_AUTH_URL }}
OPENSTACK_PASSWORD: ${{ secrets.OPENSTACK_PASSWORD }}
OPENSTACK_PROJECT_ID: ${{ secrets.OPENSTACK_PROJECT_ID }}
OPENSTACK_USER_ID: ${{ secrets.OPENSTACK_USER_ID }}
PREDICTKUBE_API_KEY: ${{ secrets.PREDICTKUBE_API_KEY }}
TEST_CLUSTER_NAME: keda-pr-run
run: |
MESSAGE="${{ github.event.comment.body }}"
Expand All @@ -186,11 +148,6 @@ jobs:
if: ${{ always() }}
run: make e2e-test-clean
env:
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_SP_APP_ID: ${{ secrets.AZURE_SP_APP_ID }}
AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }}
AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }}
TEST_CLUSTER_NAME: keda-pr-run

- name: React to comment with success
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/pr-terraform-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test Terraform
on:
- pull_request

jobs:
e2e-tests:
name: Run e2e test
runs-on: ubuntu-latest
# build-tools is built from ../../tools/build-tools.Dockerfile
container: ghcr.io/kedacore/build-tools:1.18.6
concurrency: e2e-tests
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Register workspace path
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}

- name: Run end to end tests
env:
AWS_RUN_IDENTITY_TESTS: true
AZURE_RUN_WORKLOAD_IDENTITY_TESTS: true
TEST_CLUSTER_NAME: keda-pr-run
E2E_TEST_REGEX: "azure*"
run: make e2e-test

- name: Delete all e2e related namespaces
if: ${{ always() }}
run: make e2e-test-clean
52 changes: 4 additions & 48 deletions .github/workflows/template-main-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,16 @@ jobs:
- name: Register workspace path
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}

- name: Run end to end tests
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_RUN_IDENTITY_TESTS: true
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
AZURE_APP_INSIGHTS_APP_ID: ${{ secrets.AZURE_APP_INSIGHTS_APP_ID }}
AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
AZURE_APP_INSIGHTS_INSTRUMENTATION_KEY: ${{ secrets.AZURE_APP_INSIGHTS_INSTRUMENTATION_KEY }}
AZURE_DATA_EXPLORER_DB: ${{ secrets.AZURE_DATA_EXPLORER_DB }}
AZURE_DATA_EXPLORER_ENDPOINT: ${{ secrets.AZURE_DATA_EXPLORER_ENDPOINT }}
AZURE_DEVOPS_BUILD_DEFINITION_ID: ${{ secrets.AZURE_DEVOPS_BUILD_DEFINITION_ID }}
AZURE_DEVOPS_ORGANIZATION_URL: ${{ secrets.AZURE_DEVOPS_ORGANIZATION_URL }}
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
AZURE_DEVOPS_POOL_NAME: ${{ secrets.AZURE_DEVOPS_POOL_NAME }}
AZURE_DEVOPS_PROJECT: ${{ secrets.AZURE_DEVOPS_PROJECT }}
AZURE_EVENTHBUS_MANAGEMENT_CONNECTION_STRING : ${{ secrets.AZURE_EVENTHBUS_MANAGEMENT_CONNECTION_STRING }}
AZURE_KEYVAULT_URI: ${{ secrets.AZURE_KEYVAULT_URI }}
AZURE_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.AZURE_LOG_ANALYTICS_WORKSPACE_ID }}
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_RUN_WORKLOAD_IDENTITY_TESTS: true
AZURE_SERVICE_BUS_CONNECTION_STRING: ${{ secrets.AZURE_SERVICE_BUS_CONNECTION_STRING }}
AZURE_SERVICE_BUS_ALTERNATIVE_CONNECTION_STRING: ${{ secrets.AZURE_SERVICE_BUS_ALTERNATIVE_CONNECTION_STRING }}
AZURE_SP_APP_ID: ${{ secrets.AZURE_SP_APP_ID }}
AZURE_SP_OBJECT_ID: ${{ secrets.AZURE_SP_OBJECT_ID }}
AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
AZURE_SP_ALTERNATIVE_APP_ID: ${{ secrets.AZURE_SP_ALTERNATIVE_APP_ID }}
AZURE_SP_ALTERNATIVE_OBJECT_ID: ${{ secrets.AZURE_SP_ALTERNATIVE_OBJECT_ID }}
AZURE_SP_ALTERNATIVE_KEY: ${{ secrets.AZURE_SP_ALTERNATIVE_KEY }}
AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }}
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }}
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY}}
DATADOG_APP_KEY: ${{ secrets.DATADOG_APP_KEY}}
DATADOG_SITE: ${{ secrets.DATADOG_SITE}}
GCP_SP_KEY: ${{ secrets.GCP_SP_KEY }}
NEWRELIC_ACCOUNT_ID: ${{ secrets.NEWRELIC_ACCOUNT_ID}}
NEWRELIC_API_KEY: ${{ secrets.NEWRELIC_API_KEY}}
NEWRELIC_LICENSE: ${{ secrets.NEWRELIC_LICENSE}}
OIDC_ISSUER_URL: ${{ secrets.OIDC_ISSUER_URLNIGHTLY }}
OPENSTACK_AUTH_URL: ${{ secrets.OPENSTACK_AUTH_URL }}
OPENSTACK_PASSWORD: ${{ secrets.OPENSTACK_PASSWORD }}
OPENSTACK_PROJECT_ID: ${{ secrets.OPENSTACK_PROJECT_ID }}
OPENSTACK_USER_ID: ${{ secrets.OPENSTACK_USER_ID }}
PREDICTKUBE_API_KEY: ${{ secrets.PREDICTKUBE_API_KEY }}
run: make e2e-test

- name: Delete all e2e related namespaces
if: ${{ always() }}
run: make e2e-test-clean
env:
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_SP_APP_ID: ${{ secrets.AZURE_SP_APP_ID }}
AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }}
AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }}
14 changes: 7 additions & 7 deletions .github/workflows/v1-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:

- name: Run end to end tests
env:
AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }}
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_SP_APP_ID: ${{ secrets.AZURE_SP_APP_ID }}
AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }}
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
AZURE_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.AZURE_LOG_ANALYTICS_WORKSPACE_ID }}
TF_AZURE_SUBSCRIPTION: ${{ secrets.TF_AZURE_SUBSCRIPTION }}
TF_AZURE_RESOURCE_GROUP: ${{ secrets.TF_AZURE_RESOURCE_GROUP }}
TF_AZURE_SP_APP_ID: ${{ secrets.TF_AZURE_SP_APP_ID }}
TF_AZURE_SP_KEY: ${{ secrets.TF_AZURE_SP_KEY }}
TF_AZURE_SP_TENANT: ${{ secrets.TF_AZURE_SP_TENANT }}
TF_AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.TF_AZURE_STORAGE_CONNECTION_STRING }}
TF_AZURE_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.TF_AZURE_LOG_ANALYTICS_WORKSPACE_ID }}
run: make e2e-test
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ test: manifests generate fmt vet envtest install-test-deps ## Run tests and expo

.PHONY: get-cluster-context
get-cluster-context: ## Get Azure cluster context.
@az login --service-principal -u $(AZURE_SP_APP_ID) -p "$(AZURE_SP_KEY)" --tenant $(AZURE_SP_TENANT)
@az login --service-principal -u $(TF_AZURE_SP_APP_ID) -p "$(TF_AZURE_SP_KEY)" --tenant $(TF_AZURE_SP_TENANT)
@az aks get-credentials \
--name $(TEST_CLUSTER_NAME) \
--subscription $(AZURE_SUBSCRIPTION) \
--resource-group $(AZURE_RESOURCE_GROUP)
--subscription $(TF_AZURE_SUBSCRIPTION) \
--resource-group $(TF_AZURE_RESOURCE_GROUP)

.PHONY: e2e-test
e2e-test: get-cluster-context ## Run e2e tests against Azure cluster.
Expand Down Expand Up @@ -252,7 +252,7 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
if [ "$(AZURE_RUN_WORKLOAD_IDENTITY_TESTS)" = true ]; then \
cd config/service_account && \
$(KUSTOMIZE) edit add label --force azure.workload.identity/use:true; \
$(KUSTOMIZE) edit add annotation --force azure.workload.identity/client-id:${AZURE_SP_APP_ID} azure.workload.identity/tenant-id:${AZURE_SP_TENANT}; \
$(KUSTOMIZE) edit add annotation --force azure.workload.identity/client-id:${TF_AZURE_IDENTITY_1_APP_ID} azure.workload.identity/tenant-id:${TF_AZURE_SP_TENANT}; \
fi
if [ "$(AWS_RUN_IDENTITY_TESTS)" = true ]; then \
cd config/service_account && \
Expand Down
4 changes: 2 additions & 2 deletions controllers/keda/hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func setupTest(health map[string]v1alpha1.HealthStatus, scaler *mock_scalers.Moc
scalersCache := cache.ScalersCache{
Scalers: []cache.ScalerBuilder{{
Scaler: scaler,
Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) {
return scaler, &scalers.ScalerConfig{}, nil
Factory: func() (scalers.Scaler, error) {
return scaler, nil
},
}},
Logger: logr.Discard(),
Expand Down
26 changes: 0 additions & 26 deletions controllers/keda/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,6 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(ctx context.Context, logg
return "ScaledObject doesn't have correct Idle/Min/Max Replica Counts specification", err
}

err = r.checkTriggerNamesAreUnique(scaledObject)
if err != nil {
return "ScaledObject doesn't have correct triggers specification", err
}

// Create a new HPA or update existing one according to ScaledObject
newHPACreated, err := r.ensureHPAForScaledObjectExists(ctx, logger, scaledObject, &gvkr)
if err != nil {
Expand Down Expand Up @@ -362,27 +357,6 @@ func (r *ScaledObjectReconciler) checkTargetResourceIsScalable(ctx context.Conte
return gvkr, nil
}

// checkTriggerNamesAreUnique checks that all triggerNames in ScaledObject are unique
func (r *ScaledObjectReconciler) checkTriggerNamesAreUnique(scaledObject *kedav1alpha1.ScaledObject) error {
triggersCount := len(scaledObject.Spec.Triggers)

if triggersCount > 1 {
triggerNames := make(map[string]bool, triggersCount)
for i := 0; i < triggersCount; i++ {
name := scaledObject.Spec.Triggers[i].Name
if name != "" {
if _, found := triggerNames[name]; found {
// found duplicate name
return fmt.Errorf("triggerName=%s is defined multiple times in the ScaledObject, but it must be unique", name)
}
triggerNames[name] = true
}
}
}

return nil
}

// checkReplicaCountBoundsAreValid checks that Idle/Min/Max ReplicaCount defined in ScaledObject are correctly specified
// ie. that Min is not greater then Max or Idle greater or equal to Min
func (r *ScaledObjectReconciler) checkReplicaCountBoundsAreValid(scaledObject *kedav1alpha1.ScaledObject) error {
Expand Down
69 changes: 6 additions & 63 deletions controllers/keda/scaledobject_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ var _ = Describe("ScaledObjectController", func() {

testScalers = append(testScalers, cache.ScalerBuilder{
Scaler: s,
Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) {
scaler, err := scalers.NewPrometheusScaler(config)
return scaler, config, err
Factory: func() (scalers.Scaler, error) {
return scalers.NewPrometheusScaler(config)
},
})
for _, metricSpec := range s.GetMetricSpecForScaling(context.Background()) {
Expand Down Expand Up @@ -162,8 +161,8 @@ var _ = Describe("ScaledObjectController", func() {
scalersCache := cache.ScalersCache{
Scalers: []cache.ScalerBuilder{{
Scaler: s,
Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) {
return s, config, nil
Factory: func() (scalers.Scaler, error) {
return s, nil
},
}},
}
Expand Down Expand Up @@ -206,8 +205,8 @@ var _ = Describe("ScaledObjectController", func() {

testScalers = append(testScalers, cache.ScalerBuilder{
Scaler: s,
Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) {
return s, config, nil
Factory: func() (scalers.Scaler, error) {
return s, nil
},
})
}
Expand Down Expand Up @@ -660,62 +659,6 @@ var _ = Describe("ScaledObjectController", func() {
return so.Status.Conditions.GetReadyCondition().Status
}, 20*time.Second).Should(Equal(metav1.ConditionFalse))
})

It("doesn't allow non-unique triggerName in ScaledObject", func() {
deploymentName := "non-unique-triggername"
soName := "so-" + deploymentName

triggerName := "non-unique"

// Create the scaling target.
err := k8sClient.Create(context.Background(), generateDeployment(deploymentName))
Expect(err).ToNot(HaveOccurred())

var five int32 = 5
var ten int32 = 10

// Create the ScaledObject with two triggers
so := &kedav1alpha1.ScaledObject{
ObjectMeta: metav1.ObjectMeta{Name: soName, Namespace: "default"},
Spec: kedav1alpha1.ScaledObjectSpec{
ScaleTargetRef: &kedav1alpha1.ScaleTarget{
Name: deploymentName,
},
IdleReplicaCount: &ten,
MinReplicaCount: &five,
Triggers: []kedav1alpha1.ScaleTriggers{
{
Type: "cron",
Name: triggerName,
Metadata: map[string]string{
"timezone": "UTC",
"start": "0 * * * *",
"end": "1 * * * *",
"desiredReplicas": "1",
},
},
{
Type: "cron",
Name: triggerName,
Metadata: map[string]string{
"timezone": "UTC",
"start": "10 * * * *",
"end": "11 * * * *",
"desiredReplicas": "1",
},
},
},
},
}
err = k8sClient.Create(context.Background(), so)
Ω(err).ToNot(HaveOccurred())

Eventually(func() metav1.ConditionStatus {
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: soName, Namespace: "default"}, so)
Ω(err).ToNot(HaveOccurred())
return so.Status.Conditions.GetReadyCondition().Status
}, 20*time.Second).Should(Equal(metav1.ConditionFalse))
})
})

It("scaleobject ready condition 'False/Unknow' to 'True' will requeue", func() {
Expand Down
Loading

0 comments on commit 18d207a

Please sign in to comment.