mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 07:28:06 +00:00
Adjusting logging level on various logs
This commit is contained in:
@@ -88,6 +88,24 @@ To further configure the 1Password Kubernetes Operator the following Environment
|
|||||||
- **MANAGE_CONNECT** *(default: false)*: If set to true, on deployment of the operator, a default configuration of the OnePassword Connect Service will be deployed to the current namespace.
|
- **MANAGE_CONNECT** *(default: false)*: If set to true, on deployment of the operator, a default configuration of the OnePassword Connect Service will be deployed to the current namespace.
|
||||||
- **AUTO_RESTART** (default: false): If set to true, the operator will restart any deployment using a secret from 1Password Connect. This can be overwritten by namespace, deployment, or individual secret. More details on AUTO_RESTART can be found in the ["Configuring Automatic Rolling Restarts of Deployments"](#configuring-automatic-rolling-restarts-of-deployments) section.
|
- **AUTO_RESTART** (default: false): If set to true, the operator will restart any deployment using a secret from 1Password Connect. This can be overwritten by namespace, deployment, or individual secret. More details on AUTO_RESTART can be found in the ["Configuring Automatic Rolling Restarts of Deployments"](#configuring-automatic-rolling-restarts-of-deployments) section.
|
||||||
|
|
||||||
|
You can also set the logging level by setting `--zap-log-level` as an arg on the containers to either `debug`, `info` or `error`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
.
|
||||||
|
.
|
||||||
|
.
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /manager
|
||||||
|
args:
|
||||||
|
- --leader-elect
|
||||||
|
- --zap-log-level=info
|
||||||
|
image: 1password/onepassword-operator:latest
|
||||||
|
.
|
||||||
|
.
|
||||||
|
.
|
||||||
|
```
|
||||||
To deploy the operator, simply run the following command:
|
To deploy the operator, simply run the following command:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
|
|||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
controller-gen.kubebuilder.io/version: v0.9.2
|
controller-gen.kubebuilder.io/version: v0.10.0
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: onepassworditems.onepassword.com
|
name: onepassworditems.onepassword.com
|
||||||
spec:
|
spec:
|
||||||
|
@@ -28,6 +28,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
"github.com/1Password/connect-sdk-go/connect"
|
"github.com/1Password/connect-sdk-go/connect"
|
||||||
@@ -72,7 +73,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.Info("Reconciling Deployment")
|
reqLogger.V(1).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)
|
||||||
@@ -85,7 +86,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.Info("No 1Password Annotations found")
|
reqLogger.V(1).Info("No 1Password Annotations found")
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,7 +78,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.Info("Reconciling OnePasswordItem")
|
reqLogger.V(1).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)
|
||||||
|
9
main.go
9
main.go
@@ -123,6 +123,15 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupLog.V(1).Info("this should be debug")
|
||||||
|
setupLog.V(0).Info("this should be info")
|
||||||
|
setupLog.V(-1).Info("this should be level 1")
|
||||||
|
|
||||||
|
setupLog.V(-2).Info("this is level 2")
|
||||||
|
setupLog.V(-3).Info("this is level 3 ")
|
||||||
|
setupLog.Info("this should be be here by default")
|
||||||
|
setupLog.Error(nil, "errorrr")
|
||||||
|
|
||||||
options := ctrl.Options{
|
options := ctrl.Options{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
Namespace: watchNamespace,
|
Namespace: watchNamespace,
|
||||||
|
@@ -82,7 +82,7 @@ func (h *SecretUpdateHandler) restartDeploymentsWithUpdatedSecrets(updatedSecret
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info(fmt.Sprintf("Deployment %q at namespace %q is up to date", deployment.GetName(), deployment.Namespace))
|
log.V(1).Info(fmt.Sprintf("Deployment %q at namespace %q is up to date", deployment.GetName(), deployment.Namespace))
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -131,7 +131,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.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(1).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 {
|
||||||
@@ -144,7 +144,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.Info(fmt.Sprintf("New secret path: %v and version: %v", secret.Annotations[ItemPathAnnotation], secret.Annotations[VersionAnnotation]))
|
log.V(1).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
|
||||||
|
Reference in New Issue
Block a user