mirror of
https://github.com/cert-manager/webhook-example.git
synced 2025-07-02 23:05:48 +02:00
use ns of ChallengeRequest if issuer's is empty
This commit is contained in:
parent
b6ba2aa4dd
commit
2e7a434788
2 changed files with 11 additions and 6 deletions
|
@ -108,7 +108,7 @@ else they will have undetermined behaviour when used with cert-manager.
|
||||||
**It is essential that you configure and run the test suite when creating a
|
**It is essential that you configure and run the test suite when creating a
|
||||||
DNS01 webhook.**
|
DNS01 webhook.**
|
||||||
|
|
||||||
An example Go test file has been provided in [main_test.go]().
|
An example Go test file has been provided in [main_test.go](./main_test.go).
|
||||||
|
|
||||||
Before you can run the test suite, you need to download the test binaries:
|
Before you can run the test suite, you need to download the test binaries:
|
||||||
|
|
||||||
|
|
15
main.go
15
main.go
|
@ -7,7 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
@ -82,7 +81,7 @@ type sotoonDNSProviderConfig struct {
|
||||||
// `issuer.spec.acme.dns01.providers.webhook.config` field.
|
// `issuer.spec.acme.dns01.providers.webhook.config` field.
|
||||||
|
|
||||||
Endpoint string `json:"endpoint" validate:"url"`
|
Endpoint string `json:"endpoint" validate:"url"`
|
||||||
Namespace string `json:"namespace" validate:"hostname_rfc1123"`
|
Namespace string `json:"namespace" validate:"omitempty,hostname_rfc1123"`
|
||||||
APITokenSecretRef corev1.SecretKeySelector `json:"apiTokenSecretRef"`
|
APITokenSecretRef corev1.SecretKeySelector `json:"apiTokenSecretRef"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +232,7 @@ func removeTXTRecord(sotoonClient *rest.RESTClient, zone *v1beta1.DomainZone, su
|
||||||
// cert-manager itself will later perform a self check to ensure that the
|
// cert-manager itself will later perform a self check to ensure that the
|
||||||
// solver has correctly configured the DNS provider.
|
// solver has correctly configured the DNS provider.
|
||||||
func (c *sotoonDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
func (c *sotoonDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||||
cfg, err := loadConfig(ch.Config)
|
cfg, err := loadConfig(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -268,7 +267,7 @@ func (c *sotoonDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||||
// This is in order to facilitate multiple DNS validations for the same domain
|
// This is in order to facilitate multiple DNS validations for the same domain
|
||||||
// concurrently.
|
// concurrently.
|
||||||
func (c *sotoonDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
func (c *sotoonDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
||||||
cfg, err := loadConfig(ch.Config)
|
cfg, err := loadConfig(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -319,7 +318,9 @@ func (c *sotoonDNSProviderSolver) Initialize(kubeClientConfig *rest.Config, stop
|
||||||
|
|
||||||
// loadConfig is a small helper function that decodes JSON configuration into
|
// loadConfig is a small helper function that decodes JSON configuration into
|
||||||
// the typed config struct.
|
// the typed config struct.
|
||||||
func loadConfig(cfgJSON *extapi.JSON) (*sotoonDNSProviderConfig, error) {
|
func loadConfig(ch *v1alpha1.ChallengeRequest) (*sotoonDNSProviderConfig, error) {
|
||||||
|
cfgJSON := ch.Config
|
||||||
|
|
||||||
cfg := &sotoonDNSProviderConfig{}
|
cfg := &sotoonDNSProviderConfig{}
|
||||||
// handle the 'base case' where no configuration has been provided
|
// handle the 'base case' where no configuration has been provided
|
||||||
if cfgJSON == nil {
|
if cfgJSON == nil {
|
||||||
|
@ -334,6 +335,10 @@ func loadConfig(cfgJSON *extapi.JSON) (*sotoonDNSProviderConfig, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Namespace == "" {
|
||||||
|
cfg.Namespace = ch.ResourceNamespace
|
||||||
|
}
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue