Skip to content

Commit

Permalink
Add new annotation krane.shopify.io/skip-endpoint-validation to ski…
Browse files Browse the repository at this point in the history
…p the validation of service endpoints (#960)
  • Loading branch information
jerr authored Aug 6, 2024
1 parent 824c49b commit 6beb0c1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ before the deployment is considered successful.
- _Accepted values_: `create`, `replace`, and `replace-force`
- _Warning_: Resources whose deploy method is overridden are no longer subject to pruning on deploy.
- This feature is _experimental_ and may be removed at any time.
- `krane.shopify.io/skip-endpoint-validation`: Skip endpoint validation for the service.
- _Compatibility_: Service
- _Default_: `false`
- `true`: Endpoint validation is not performed during the deployment of the service.


### Running tasks at the beginning of a deploy
Expand Down
8 changes: 8 additions & 0 deletions lib/krane/kubernetes_resource/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?

Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions test/fixtures/for_unit_tests/service_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions test/unit/krane/kubernetes_resource/service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6beb0c1

Please sign in to comment.