name_truncation_test.yaml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. suite: test componentName DNS-label name truncation
  2. templates:
  3. - webhook-service.yaml
  4. - cert-controller-service.yaml
  5. - cert-controller-deployment.yaml
  6. - service.yaml
  7. - validatingwebhook.yaml
  8. - webhook-certificate.yaml
  9. tests:
  10. - it: should not alter names that are well under the 63-char DNS label limit
  11. set:
  12. fullnameOverride: my-release
  13. webhook.create: true
  14. webhook.service.enabled: true
  15. template: webhook-service.yaml
  16. asserts:
  17. - equal:
  18. path: metadata.name
  19. value: my-release-webhook
  20. - matchRegex:
  21. path: metadata.name
  22. pattern: ^.{1,63}$
  23. - it: should truncate from the right and preserve the name prefix for a short suffix (-webhook 8 chars)
  24. # fullnameOverride: 60 chars ("external-secrets-production-cluster-for-long-release-testing").
  25. # componentName maxLen = 63 - 8 = 55; trunc(55) keeps the first 55 chars of the
  26. # base name so appending the 8-char suffix produces exactly 63 chars total.
  27. set:
  28. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  29. webhook.create: true
  30. webhook.service.enabled: true
  31. template: webhook-service.yaml
  32. asserts:
  33. - equal:
  34. path: metadata.name
  35. value: "external-secrets-production-cluster-for-long-release-te-webhook"
  36. - matchRegex:
  37. path: metadata.name
  38. pattern: ^.{1,63}$
  39. - it: should truncate from the right for the longest suffix in the chart (-cert-controller-metrics 24 chars)
  40. # Same 60-char fullnameOverride.
  41. # componentName maxLen = 63 - 24 = 39; trunc(39) keeps the first 39 chars,
  42. # so the total is exactly 63. This is the primary failure case from issue #1997.
  43. set:
  44. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  45. certController.create: true
  46. certController.metrics.service.enabled: true
  47. template: cert-controller-service.yaml
  48. asserts:
  49. - equal:
  50. path: metadata.name
  51. value: "external-secrets-production-cluster-for-cert-controller-metrics"
  52. - matchRegex:
  53. path: metadata.name
  54. pattern: ^.{1,63}$
  55. - it: should strip a trailing dash when the truncation point falls on a hyphen
  56. # fullnameOverride: 60 chars with a hyphen at position 55
  57. # ("external-secrets-for-production-release-cluster-naming-tests").
  58. # trunc(55) yields the first 54 chars plus a trailing "-"; trimSuffix "-"
  59. # removes it, leaving 54 chars, so the result is 54 + 8 = 62 chars with no
  60. # double-dash at the suffix boundary.
  61. set:
  62. fullnameOverride: "external-secrets-for-production-release-cluster-naming-tests"
  63. webhook.create: true
  64. webhook.service.enabled: true
  65. template: webhook-service.yaml
  66. asserts:
  67. - equal:
  68. path: metadata.name
  69. value: "external-secrets-for-production-release-cluster-naming-webhook"
  70. - matchRegex:
  71. path: metadata.name
  72. pattern: ^.{1,63}$
  73. - it: service.yaml - should truncate -metrics suffix (8 chars) when fullname is long
  74. # service.yaml uses componentName with suffix "-metrics" (8 chars), same
  75. # maxLen=55 as -webhook. Confirms the main controller metrics Service is
  76. # covered by the helper, not just webhook/cert-controller Services.
  77. set:
  78. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  79. metrics.service.enabled: true
  80. template: service.yaml
  81. asserts:
  82. - equal:
  83. path: metadata.name
  84. value: "external-secrets-production-cluster-for-long-release-te-metrics"
  85. - matchRegex:
  86. path: metadata.name
  87. pattern: ^.{1,63}$
  88. - it: validatingwebhook.yaml - clientConfig.service.name must match the truncated webhook Service name
  89. # The ValidatingWebhook routes admission requests to the webhook Service.
  90. # If service.name here diverges from the Service metadata.name, TLS
  91. # routing breaks. Both must use the same componentName helper output.
  92. set:
  93. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  94. webhook.create: true
  95. template: validatingwebhook.yaml
  96. documentIndex: 0
  97. asserts:
  98. - equal:
  99. path: webhooks[0].clientConfig.service.name
  100. value: "external-secrets-production-cluster-for-long-release-te-webhook"
  101. - matchRegex:
  102. path: webhooks[0].clientConfig.service.name
  103. pattern: ^.{1,63}$
  104. - it: webhook-certificate.yaml - dnsNames must match the truncated webhook Service hostname
  105. # cert-manager issues TLS certs for the webhook Service. The SAN must
  106. # match the Service name exactly or the TLS handshake fails. Both
  107. # commonName and the first dnsName entry use componentName so they stay
  108. # in sync with the Service even when the release name is long.
  109. set:
  110. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  111. webhook.create: true
  112. webhook.certManager.enabled: true
  113. webhook.certManager.cert.create: true
  114. webhook.certManager.cert.issuerRef:
  115. name: selfsigned
  116. kind: ClusterIssuer
  117. template: webhook-certificate.yaml
  118. asserts:
  119. - equal:
  120. path: spec.commonName
  121. value: "external-secrets-production-cluster-for-long-release-te-webhook"
  122. - equal:
  123. path: spec.dnsNames[0]
  124. value: "external-secrets-production-cluster-for-long-release-te-webhook"
  125. - matchRegex:
  126. path: spec.commonName
  127. pattern: ^.{1,63}$
  128. - it: "cert-controller --service-name must match webhook Service name when truncation fires"
  129. # cert-controller-deployment uses componentName with -webhook suffix for
  130. # --service-name. The value must equal the webhook Service metadata.name or
  131. # the cert-controller can't locate the Service and TLS breaks.
  132. set:
  133. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  134. certController.create: true
  135. webhook.create: true
  136. template: cert-controller-deployment.yaml
  137. asserts:
  138. - contains:
  139. path: spec.template.spec.containers[0].args
  140. content: "--service-name=external-secrets-production-cluster-for-long-release-te-webhook"
  141. - it: "webhook Service metadata.name must match cert-controller --service-name when truncation fires"
  142. # Mirror of the above: the webhook Service must be named identically to what
  143. # cert-controller passes as --service-name. Both use componentName(-webhook)
  144. # so they stay in sync; this test surfaces any future divergence.
  145. set:
  146. fullnameOverride: "external-secrets-production-cluster-for-long-release-testing"
  147. webhook.create: true
  148. webhook.service.enabled: true
  149. template: webhook-service.yaml
  150. asserts:
  151. - equal:
  152. path: metadata.name
  153. value: "external-secrets-production-cluster-for-long-release-te-webhook"
  154. - matchRegex:
  155. path: metadata.name
  156. pattern: ^.{1,63}$