diff --git a/CHANGELOG.md b/CHANGELOG.md index 909fc30bd..fc3e9378c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## next +*Features* + +- Enable the option to bypass endpoint validation for a service by using the annotation `krane.shopify.io/skip-endpoint-validation: true`. + ## 3.6.0 - Test against k8s 1.29, 1.30 diff --git a/lib/krane/kubernetes_resource/service.rb b/lib/krane/kubernetes_resource/service.rb index 78a7f35c3..64909fd51 100644 --- a/lib/krane/kubernetes_resource/service.rb +++ b/lib/krane/kubernetes_resource/service.rb @@ -5,6 +5,7 @@ module Krane class Service < KubernetesResource TIMEOUT = 7.minutes SYNC_DEPENDENCIES = %w(Pod Deployment StatefulSet) + SKIP_ENDPOINT_VALIDATION_ANNOTATION = 'skip-endpoint-validation' def sync(cache) super @@ -59,6 +60,9 @@ def exposes_zero_replica_workload? end def requires_endpoints? + # skip validation if the annotation is present + return false if skip_endpoint_validation + # services of type External don't have endpoints return false if external_name_svc? @@ -96,5 +100,9 @@ def requires_publishing? def published? @instance_data.dig('status', 'loadBalancer', 'ingress').present? end + + def skip_endpoint_validation + krane_annotation_value(SKIP_ENDPOINT_VALIDATION_ANNOTATION) == 'true' + end end end diff --git a/test/fixtures/for_unit_tests/service_test.yml b/test/fixtures/for_unit_tests/service_test.yml index cf3e71955..74da1a90d 100644 --- a/test/fixtures/for_unit_tests/service_test.yml +++ b/test/fixtures/for_unit_tests/service_test.yml @@ -215,3 +215,13 @@ spec: type: LoadBalancer selector: type: standard +--- +apiVersion: v1 +kind: Service +metadata: + name: standard-with-skip-endpoint-validation-annotation + annotations: + krane.shopify.io/skip-endpoint-validation: 'true' +spec: + selector: + type: standard diff --git a/test/unit/krane/kubernetes_resource/service_test.rb b/test/unit/krane/kubernetes_resource/service_test.rb index 9cc75495f..0c7dbcabd 100644 --- a/test/unit/krane/kubernetes_resource/service_test.rb +++ b/test/unit/krane/kubernetes_resource/service_test.rb @@ -189,6 +189,21 @@ def test_ensures_populated_status_for_load_balancers assert_equal("Selects at least 1 pod", svc.status) end + def test_service_with_skip_endpoint_validation_annotation_does_not_require_endpoints + svc_def = service_fixture('standard-with-skip-endpoint-validation-annotation') + svc = build_service(svc_def) + + stub_kind_get("Service", items: [svc_def]) + stub_kind_get("Deployment", items: deployment_fixtures) + stub_kind_get("Pod", items: []) + stub_kind_get("StatefulSet", items: []) + svc.sync(build_resource_cache) + + assert(svc.exists?) + assert(svc.deploy_succeeded?) + assert_equal("Doesn't require any endpoints", svc.status) + end + private def build_service(definition)