Added additional logging

This commit is contained in:
Marcus Noble 2020-05-02 13:03:39 +01:00
parent 36cd74f70f
commit 27e5034d99
2 changed files with 5 additions and 3 deletions

View File

@ -77,7 +77,6 @@ func (op *Client) GetSecret(vault, secretID string) (*Secret, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
item := response{} item := response{}
if err := json.Unmarshal(res, &item); err != nil { if err := json.Unmarshal(res, &item); err != nil {
return nil, err return nil, err

View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"os" "os"
"os/user" "os/user"
"time" "time"
@ -38,19 +39,21 @@ func main() {
} }
for { for {
log.Println("[DEBUG] Syncing secrets")
list, err := clientset.CoreV1().Secrets(apiv1.NamespaceAll).List(context.Background(), metav1.ListOptions{}) list, err := clientset.CoreV1().Secrets(apiv1.NamespaceAll).List(context.Background(), metav1.ListOptions{})
if err != nil { if err != nil {
panic(err) panic(err)
} }
for _, s := range list.Items { for _, s := range list.Items {
if passwordID, exists := s.ObjectMeta.Annotations[idAnnotation]; exists { if passwordID, exists := s.ObjectMeta.Annotations[idAnnotation]; exists {
log.Printf("[INFO] Syncing secret %s with 1Password secret %s\n", s.GetName(), passwordID)
keys := parseAnnotations(s.ObjectMeta.Annotations) keys := parseAnnotations(s.ObjectMeta.Annotations)
vault := keys["vault"] vault := keys["vault"]
item, err := opClient.GetSecret(vault, passwordID) item, err := opClient.GetSecret(vault, passwordID)
if err != nil { if err != nil {
fmt.Println("[ERROR] Could not get secret", err) log.Println("[ERROR] Could not get secret", err)
continue continue
} }
@ -69,7 +72,7 @@ func main() {
} }
if _, err := clientset.CoreV1().Secrets(s.GetNamespace()).Update(context.Background(), &s, metav1.UpdateOptions{}); err != nil { if _, err := clientset.CoreV1().Secrets(s.GetNamespace()).Update(context.Background(), &s, metav1.UpdateOptions{}); err != nil {
fmt.Println("[ERROR] Could not update secret value", err) log.Println("[ERROR] Could not update secret value", err)
continue continue
} }
} }