Skip to content

Commit

Permalink
feat: 1. test 2. helm charts
Browse files Browse the repository at this point in the history
  • Loading branch information
er1c-zh committed Dec 15, 2024
1 parent 1a103dc commit be3e1a0
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release-charts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release Charts

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.0.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/miekg/dns v1.1.59 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down Expand Up @@ -73,6 +74,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs=
github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -205,6 +207,8 @@ golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJ
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {

// sets a record in the DNS provider's console
resp, err := namesilo.Call[namesilo.Response](apiKey, "dnsAddRecord", map[string]string{
"domain": ch.ResolvedZone,
"domain": namesilo.GetDomainFromZone(ch.ResolvedZone),
"rrtype": "TXT",
"rrhost": strings.TrimSuffix(ch.ResolvedFQDN, "."+ch.ResolvedZone),
"rrvalue": ch.Key,
Expand Down Expand Up @@ -142,7 +142,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
}
// 1. fetch the TXT record id
listResp, err := namesilo.Call[namesilo.DnsRecordListResponse](apiKey, "dnsListRecords", map[string]string{
"domain": ch.ResolvedZone,
"domain": namesilo.GetDomainFromZone(ch.ResolvedZone),
})
if err != nil {
utils.Log("Error listing TXT records for %s, %s: %s", ch.ResolvedFQDN, ch.ResolvedZone, err.Error())
Expand All @@ -153,7 +153,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
}
targetRecordID := ""
for _, r := range listResp.Reply.ResourceRecord {
if r.Host == ch.ResolvedFQDN && r.Type == "TXT" && r.Value == ch.Key {
if r.Host == namesilo.GetDomainFromZone(ch.ResolvedFQDN) && r.Type == "TXT" && r.Value == ch.Key {
targetRecordID = r.ResourceID
break
}
Expand All @@ -169,7 +169,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {

// 2. delete the TXT record
deleteResp, err := namesilo.Call[namesilo.Response](apiKey, "dnsDeleteRecord", map[string]string{
"domain": ch.ResolvedFQDN,
"domain": namesilo.GetDomainFromZone(ch.ResolvedZone),
"rrid": targetRecordID,
})
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"os"
"testing"

acmetest "github.com/cert-manager/cert-manager/test/acme"
)

var (
zone = os.Getenv("TEST_ZONE_NAME")
)

func TestRunsSuite(t *testing.T) {
// The manifest path should contain a file named config.json that is a
// snippet of valid configuration that should be included on the
// ChallengeRequest passed as part of the test cases.
//

// Uncomment the below fixture when implementing your custom DNS provider
fixture := acmetest.NewFixture(&customDNSProviderSolver{},
acmetest.SetResolvedZone(zone),
acmetest.SetAllowAmbientCredentials(false),
acmetest.SetManifestPath("testdata/namesilo"),
acmetest.SetDNSServer("202.46.34.75:53"),
// acmetest.SetBinariesPath("_test/kubebuilder/bin"),
)
//need to uncomment and RunConformance delete runBasic and runExtended once https://github.com/cert-manager/cert-manager/pull/4835 is merged
//fixture.RunConformance(t)
fixture.RunBasic(t)
fixture.RunExtended(t)
}
4 changes: 4 additions & 0 deletions namesilo/namesilo.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ func Call[Resp any](apiKey string, operation string, params map[string]string) (
}
return resp, nil
}

func GetDomainFromZone(fqdn string) string {
return strings.TrimSuffix(fqdn, ".")
}
7 changes: 6 additions & 1 deletion testdata/namesilo/config.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{}
{
"apiKey": {
"name": "namesilo-api-key",
"key": "namesilo-api-key"
}
}
6 changes: 6 additions & 0 deletions testdata/namesilo/namesilo-api-key.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Secret
metadata:
name: namesilo-api-key
data:
namesilo-api-key: replace-with-base64-namesilo-api-key
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package utils
import "fmt"

func Log(format string, args ...any) {
fmt.Printf(format, args...)
fmt.Printf(format+"\n", args...)
}

0 comments on commit be3e1a0

Please sign in to comment.