mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 07:28:06 +00:00
Converting logging enums to constants
This commit is contained in:
@@ -74,7 +74,7 @@ type DeploymentReconciler struct {
|
|||||||
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile
|
||||||
func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
reqLogger := logDeployment.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
|
reqLogger := logDeployment.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
|
||||||
reqLogger.V(int(logs.DebugLevel)).Info("Reconciling Deployment")
|
reqLogger.V(logs.DebugLevel).Info("Reconciling Deployment")
|
||||||
|
|
||||||
deployment := &appsv1.Deployment{}
|
deployment := &appsv1.Deployment{}
|
||||||
err := r.Get(context.Background(), req.NamespacedName, deployment)
|
err := r.Get(context.Background(), req.NamespacedName, deployment)
|
||||||
@@ -87,7 +87,7 @@ func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||||||
|
|
||||||
annotations, annotationsFound := op.GetAnnotationsForDeployment(deployment, r.OpAnnotationRegExp)
|
annotations, annotationsFound := op.GetAnnotationsForDeployment(deployment, r.OpAnnotationRegExp)
|
||||||
if !annotationsFound {
|
if !annotationsFound {
|
||||||
reqLogger.V(int(logs.DebugLevel)).Info("No 1Password Annotations found")
|
reqLogger.V(logs.DebugLevel).Info("No 1Password Annotations found")
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -79,7 +79,7 @@ type OnePasswordItemReconciler struct {
|
|||||||
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile
|
||||||
func (r *OnePasswordItemReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
func (r *OnePasswordItemReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
reqLogger := logOnePasswordItem.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
|
reqLogger := logOnePasswordItem.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
|
||||||
reqLogger.V(int(logs.DebugLevel)).Info("Reconciling OnePasswordItem")
|
reqLogger.V(logs.DebugLevel).Info("Reconciling OnePasswordItem")
|
||||||
|
|
||||||
onepassworditem := &onepasswordv1.OnePasswordItem{}
|
onepassworditem := &onepasswordv1.OnePasswordItem{}
|
||||||
err := r.Get(context.Background(), req.NamespacedName, onepassworditem)
|
err := r.Get(context.Background(), req.NamespacedName, onepassworditem)
|
||||||
|
@@ -3,11 +3,9 @@ package logs
|
|||||||
// A Level is a logging priority. Lower levels are more important.
|
// A Level is a logging priority. Lower levels are more important.
|
||||||
// All levels have been multipled by -1 to ensure compatibilty
|
// All levels have been multipled by -1 to ensure compatibilty
|
||||||
// between zapcore and logr
|
// between zapcore and logr
|
||||||
type Level int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorLevel Level = iota - 2
|
ErrorLevel = -2
|
||||||
WarnLevel
|
WarnLevel = -1
|
||||||
InfoLevel
|
InfoLevel = 0
|
||||||
DebugLevel
|
DebugLevel = 1
|
||||||
)
|
)
|
||||||
|
@@ -83,7 +83,7 @@ func (h *SecretUpdateHandler) restartDeploymentsWithUpdatedSecrets(updatedSecret
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.V(int(logs.DebugLevel)).Info(fmt.Sprintf("Deployment %q at namespace %q is up to date", deployment.GetName(), deployment.Namespace))
|
log.V(logs.DebugLevel).Info(fmt.Sprintf("Deployment %q at namespace %q is up to date", deployment.GetName(), deployment.Namespace))
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -132,7 +132,7 @@ func (h *SecretUpdateHandler) updateKubernetesSecrets() (map[string]map[string]*
|
|||||||
|
|
||||||
if currentVersion != itemVersion || secret.Annotations[ItemPathAnnotation] != itemPathString {
|
if currentVersion != itemVersion || secret.Annotations[ItemPathAnnotation] != itemPathString {
|
||||||
if isItemLockedForForcedRestarts(item) {
|
if isItemLockedForForcedRestarts(item) {
|
||||||
log.V(int(logs.DebugLevel)).Info(fmt.Sprintf("Secret '%v' has been updated in 1Password but is set to be ignored. Updates to an ignored secret will not trigger an update to a kubernetes secret or a rolling restart.", secret.GetName()))
|
log.V(logs.DebugLevel).Info(fmt.Sprintf("Secret '%v' has been updated in 1Password but is set to be ignored. Updates to an ignored secret will not trigger an update to a kubernetes secret or a rolling restart.", secret.GetName()))
|
||||||
secret.Annotations[VersionAnnotation] = itemVersion
|
secret.Annotations[VersionAnnotation] = itemVersion
|
||||||
secret.Annotations[ItemPathAnnotation] = itemPathString
|
secret.Annotations[ItemPathAnnotation] = itemPathString
|
||||||
if err := h.client.Update(context.Background(), &secret); err != nil {
|
if err := h.client.Update(context.Background(), &secret); err != nil {
|
||||||
@@ -145,7 +145,7 @@ func (h *SecretUpdateHandler) updateKubernetesSecrets() (map[string]map[string]*
|
|||||||
secret.Annotations[VersionAnnotation] = itemVersion
|
secret.Annotations[VersionAnnotation] = itemVersion
|
||||||
secret.Annotations[ItemPathAnnotation] = itemPathString
|
secret.Annotations[ItemPathAnnotation] = itemPathString
|
||||||
secret.Data = kubeSecrets.BuildKubernetesSecretData(item.Fields, item.Files)
|
secret.Data = kubeSecrets.BuildKubernetesSecretData(item.Fields, item.Files)
|
||||||
log.V(int(logs.DebugLevel)).Info(fmt.Sprintf("New secret path: %v and version: %v", secret.Annotations[ItemPathAnnotation], secret.Annotations[VersionAnnotation]))
|
log.V(logs.DebugLevel).Info(fmt.Sprintf("New secret path: %v and version: %v", secret.Annotations[ItemPathAnnotation], secret.Annotations[VersionAnnotation]))
|
||||||
if err := h.client.Update(context.Background(), &secret); err != nil {
|
if err := h.client.Update(context.Background(), &secret); err != nil {
|
||||||
log.Error(err, "failed to update secret %s to version %d: %s", secret.Name, itemVersion, err)
|
log.Error(err, "failed to update secret %s to version %d: %s", secret.Name, itemVersion, err)
|
||||||
continue
|
continue
|
||||||
|
@@ -55,7 +55,7 @@ func GetOperatorNamespace() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
ns := strings.TrimSpace(string(nsBytes))
|
ns := strings.TrimSpace(string(nsBytes))
|
||||||
log.V(int(logs.DebugLevel)).Info("Found namespace", "Namespace", ns)
|
log.V(logs.DebugLevel).Info("Found namespace", "Namespace", ns)
|
||||||
return ns, nil
|
return ns, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user