mirror of
https://github.com/cert-manager/webhook-example.git
synced 2026-03-16 18:02:51 +01:00
configure main provider with api key secret and k8s client
This commit is contained in:
parent
b67b987b07
commit
8e6eff3855
1 changed files with 16 additions and 12 deletions
28
main.go
28
main.go
|
|
@ -6,10 +6,12 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
|
|
||||||
"github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
acme_v1alpha1 "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||||
"github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd"
|
"github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd"
|
||||||
|
meta_v1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var GroupName = os.Getenv("GROUP_NAME")
|
var GroupName = os.Getenv("GROUP_NAME")
|
||||||
|
|
@ -40,7 +42,7 @@ type customDNSProviderSolver struct {
|
||||||
// 3. uncomment the relevant code in the Initialize method below
|
// 3. uncomment the relevant code in the Initialize method below
|
||||||
// 4. ensure your webhook's service account has the required RBAC role
|
// 4. ensure your webhook's service account has the required RBAC role
|
||||||
// assigned to it for interacting with the Kubernetes APIs you need.
|
// assigned to it for interacting with the Kubernetes APIs you need.
|
||||||
//client kubernetes.Clientset
|
client *kubernetes.Clientset
|
||||||
}
|
}
|
||||||
|
|
||||||
// customDNSProviderConfig is a structure that is used to decode into when
|
// customDNSProviderConfig is a structure that is used to decode into when
|
||||||
|
|
@ -64,7 +66,8 @@ type customDNSProviderConfig struct {
|
||||||
// `issuer.spec.acme.dns01.providers.webhook.config` field.
|
// `issuer.spec.acme.dns01.providers.webhook.config` field.
|
||||||
|
|
||||||
//Email string `json:"email"`
|
//Email string `json:"email"`
|
||||||
//APIKeySecretRef v1alpha1.SecretKeySelector `json:"apiKeySecretRef"`
|
Login string `json:"login"`
|
||||||
|
APIKeySecretRef meta_v1.SecretKeySelector `json:"apiKeySecretRef"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name is used as the name for this DNS solver when referencing it on the ACME
|
// Name is used as the name for this DNS solver when referencing it on the ACME
|
||||||
|
|
@ -74,7 +77,7 @@ type customDNSProviderConfig struct {
|
||||||
// within a single webhook deployment**.
|
// within a single webhook deployment**.
|
||||||
// For example, `cloudflare` may be used as the name of a solver.
|
// For example, `cloudflare` may be used as the name of a solver.
|
||||||
func (c *customDNSProviderSolver) Name() string {
|
func (c *customDNSProviderSolver) Name() string {
|
||||||
return "my-custom-solver"
|
return "NearlyFreeSpeech"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present is responsible for actually presenting the DNS record with the
|
// Present is responsible for actually presenting the DNS record with the
|
||||||
|
|
@ -82,7 +85,7 @@ func (c *customDNSProviderSolver) Name() string {
|
||||||
// This method should tolerate being called multiple times with the same value.
|
// This method should tolerate being called multiple times with the same value.
|
||||||
// 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 *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
func (c *customDNSProviderSolver) Present(ch *acme_v1alpha1.ChallengeRequest) error {
|
||||||
cfg, err := loadConfig(ch.Config)
|
cfg, err := loadConfig(ch.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -92,6 +95,7 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||||
fmt.Printf("Decoded configuration %v", cfg)
|
fmt.Printf("Decoded configuration %v", cfg)
|
||||||
|
|
||||||
// TODO: add code that sets a record in the DNS provider's console
|
// TODO: add code that sets a record in the DNS provider's console
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +105,7 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||||
// value provided on the ChallengeRequest should be cleaned up.
|
// value provided on the ChallengeRequest should be cleaned up.
|
||||||
// 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 *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
func (c *customDNSProviderSolver) CleanUp(ch *acme_v1alpha1.ChallengeRequest) error {
|
||||||
// TODO: add code that deletes a record from the DNS provider's console
|
// TODO: add code that deletes a record from the DNS provider's console
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -119,12 +123,12 @@ func (c *customDNSProviderSolver) Initialize(kubeClientConfig *rest.Config, stop
|
||||||
///// UNCOMMENT THE BELOW CODE TO MAKE A KUBERNETES CLIENTSET AVAILABLE TO
|
///// UNCOMMENT THE BELOW CODE TO MAKE A KUBERNETES CLIENTSET AVAILABLE TO
|
||||||
///// YOUR CUSTOM DNS PROVIDER
|
///// YOUR CUSTOM DNS PROVIDER
|
||||||
|
|
||||||
//cl, err := kubernetes.NewForConfig(kubeClientConfig)
|
cl, err := kubernetes.NewForConfig(kubeClientConfig)
|
||||||
//if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//c.client = cl
|
c.client = cl
|
||||||
|
|
||||||
///// END OF CODE TO MAKE KUBERNETES CLIENTSET AVAILABLE
|
///// END OF CODE TO MAKE KUBERNETES CLIENTSET AVAILABLE
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue