diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32f7bae..c34e05d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: run: | export GOBIN=$(pwd)/bin export PATH=$PATH:$GOBIN - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager-$VERSION-linux-amd64 main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-X 'main.version=$(git describe --tags)' -X 'main.buildTime=$(date)'" -a -o manager-$VERSION-linux-amd64 main.go echo manager-$VERSION env: VERSION: ${{ steps.get_version.outputs.VERSION }} diff --git a/Makefile b/Makefile index a27ed5b..0d30754 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ teste2e: # Build manager binary manager: generate fmt vet - go build -o bin/manager main.go + go build -ldflags="-X 'main.version=$(shell git describe --tags)' -X 'main.buildTime=$(shell date)'" -o bin/manager main.go # Run against the configured Kubernetes cluster in ~/.kube/config run: generate fmt vet manifests diff --git a/adcs/ntlm_certsrv.go b/adcs/ntlm_certsrv.go index cb9235e..a1f0029 100644 --- a/adcs/ntlm_certsrv.go +++ b/adcs/ntlm_certsrv.go @@ -190,6 +190,8 @@ func (s *NtlmCertsrv) RequestCertificate(csr string, template string) (AdcsRespo log := log.Log.WithName("RequestCertificate").WithValues("template", template) var certStatus AdcsResponseStatus = Unknown + log.V(1).Info("Starting certificate request") + url := fmt.Sprintf("%s/%s", s.url, certfnsh) params := neturl.Values{ "Mode": {"newreq"}, @@ -209,7 +211,7 @@ func (s *NtlmCertsrv) RequestCertificate(csr string, template string) (AdcsRespo req.Header.Set("User-agent", "Mozilla") req.Header.Set("Content-type", ct_urlenc) - log.V(1).Info("Sending request", "request", req) + log.V(2).Info("Sending request", "request", req) res, err := s.httpClient.Do(req) if err != nil { @@ -228,7 +230,7 @@ func (s *NtlmCertsrv) RequestCertificate(csr string, template string) (AdcsRespo bodyString := string(body) - log.V(1).Info("Body", "body", bodyString) + log.V(2).Info("Body", "body", bodyString) exp := regexp.MustCompile(`certnew.cer\?ReqID=([0-9]+)&`) found := exp.FindStringSubmatch(bodyString) diff --git a/controllers/adcsrequest_controller.go b/controllers/adcsrequest_controller.go index cf1dcd1..00e5e69 100644 --- a/controllers/adcsrequest_controller.go +++ b/controllers/adcsrequest_controller.go @@ -51,10 +51,6 @@ func (r *AdcsRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) // your logic here log.Info("Processing request") - if log.V(3).Enabled() { - log.V(3).Info("Running request", "template", r.IssuerFactory.AdcsTemplateName) - } - // Fetch the AdcsRequest resource being reconciled ar := new(api.AdcsRequest) if err := r.Client.Get(ctx, req.NamespacedName, ar); err != nil { @@ -71,6 +67,10 @@ func (r *AdcsRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, err } + if log.V(3).Enabled() { + log.V(3).Info("Running request", "template", issuer.AdcsTemplateName) + } + cert, caCert, err := issuer.Issue(ctx, ar) if err != nil { // This is a local error. diff --git a/main.go b/main.go index 0aaf76c..b2be517 100644 --- a/main.go +++ b/main.go @@ -39,8 +39,10 @@ const ( ) var ( - scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") + scheme = runtime.NewScheme() + setupLog = ctrl.Log.WithName("setup") + version = "development" + buildTime = "unknown" ) func init() { @@ -83,6 +85,8 @@ func main() { ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) + setupLog.Info("Starting ADCS Issuer", "version", version, "build time", buildTime) + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr,