Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add acme resolver monitoring #4223

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions controllers/pkg/resources/named.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package resources
import (
"strings"

corev1 "k8s.io/api/core/v1"

sealos_networkmanager "github.com/dinoallo/sealos-networkmanager-protoapi"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -30,6 +32,7 @@ const (
TerminalIDLabelKey = "TerminalID"
AppLabelKey = "app"
JobNameLabelKey = "job-name"
ACMEChallengeKey = "acme.cert-manager.io/http01-solver"
KubeBlocksBackUpName = "kubeblocks-backup-data"
)

Expand Down Expand Up @@ -59,13 +62,39 @@ func NewResourceNamed(cr client.Object) *ResourceNamed {
case cr.GetName() == KubeBlocksBackUpName:
p._type = JOB
p._name = KubeBlocksBackUpName
case labels[ACMEChallengeKey] != "":
p._type = APP
p._name = getACMEResolverName(cr)
default:
p._type = OTHER
p._name = ""
}
return p
}

const (
acmesolver = "acmesolver"
acmesolverContainerArgsDomainPrefix = "--domain="
)

func getACMEResolverName(obj client.Object) string {
pod, ok := obj.(*corev1.Pod)
if !ok {
return ""
}
for _, container := range pod.Spec.Containers {
if container.Name != acmesolver {
continue
}
for _, arg := range container.Args {
if strings.HasPrefix(arg, acmesolverContainerArgsDomainPrefix) {
return acmesolver + "-" + strings.TrimPrefix(arg, acmesolverContainerArgsDomainPrefix)
}
}
}
return pod.Name
}

func (p *ResourceNamed) Type() uint8 {
return AppType[p._type]
}
Expand Down
Loading