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

Issue522: Re-evaluate log level for pravega operator #523

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions charts/pravega-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ The following table lists the configurable parameters of the pravega-operator ch
| `webhookCert.certName` | Name of the certificate, if generate is set to false | `selfsigned-cert` |
| `webhookCert.secretName` | Name of the secret created by the certificate, if generate is set to false | `selfsigned-cert-tls` |
| `watchNamespace` | Namespaces to be watched | `""` |
| `logLevel` | Specify the loging level used by operator | `"debug"` |
2 changes: 2 additions & 0 deletions charts/pravega-operator/templates/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ spec:
args: [-test]
{{- end }}
env:
- name: LOG_LEVEL
value: "{{ .Values.logLevel }}"
- name: WATCH_NAMESPACE
value: "{{ .Values.watchNamespace }}"
- name: POD_NAME
Expand Down
3 changes: 3 additions & 0 deletions charts/pravega-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ webhookCert:
## An empty string means all namespaces.
watchNamespace: ""

##Specify the loging level used by operator
logLevel: "debug"

hooks:
backoffLimit: 10
image:
Expand Down
51 changes: 30 additions & 21 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ import (
"github.com/pravega/pravega-operator/pkg/apis/pravega/v1beta1"
"github.com/pravega/pravega-operator/pkg/controller"
controllerconfig "github.com/pravega/pravega-operator/pkg/controller/config"
"github.com/pravega/pravega-operator/pkg/util"
"github.com/pravega/pravega-operator/pkg/version"
log "github.com/sirupsen/logrus"

"github.com/rs/zerolog"
log "github.com/rs/zerolog/log"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"

"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

var (
versionFlag bool
webhookFlag bool
logLevel string
)

func init() {
Expand All @@ -47,36 +47,36 @@ func init() {
}

func printVersion() {
log.Printf("pravega-operator Version: %v", version.Version)
log.Printf("Git SHA: %s", version.GitSHA)
log.Printf("Go Version: %s", runtime.Version())
log.Printf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
log.Printf("operator-sdk Version: %v", sdkVersion.Version)
log.Info().Msgf("pravega-operator Version: %v", version.Version)
log.Info().Msgf("Git SHA: %s", version.GitSHA)
log.Info().Msgf("Go Version: %s", runtime.Version())
log.Info().Msgf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
log.Info().Msgf("operator-sdk Version: %v", sdkVersion.Version)
}

func main() {
flag.Parse()
logf.SetLogger(logf.ZapLogger(false))
zerolog.SetGlobalLevel(util.LogLevel())

flag.Parse()
printVersion()

if versionFlag {
os.Exit(0)
}

if controllerconfig.TestMode {
log.Warn("----- Running in test mode. Make sure you are NOT in production -----")
log.Warn().Msg("----- Running in test mode. Make sure you are NOT in production -----")
}

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
log.Fatal(err, "failed to get watch namespace")
log.Error().Err(err).Msg("failed to get watch namespace")
}

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
log.Fatal(err)
log.Error().Err(err).Msg("")
}

// Become the leader before proceeding
Expand All @@ -86,33 +86,42 @@ func main() {
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})

if err != nil {
log.Fatal(err)
log.Fatal().
Err(err).
Msg("")
}

log.Print("Registering Components")
log.Info().Msg("Registering Components")

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
log.Fatal().
Err(err).
Msg("")

}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
log.Fatal().
Err(err).
Msg("")
}

v1beta1.Mgr = mgr
if webhookFlag {
if err := (&v1beta1.PravegaCluster{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook %s", err.Error())
log.Error().Err(err).Msgf("unable to create webhook %s", err.Error())
os.Exit(1)
}
}

log.Print("Starting the Cmd")
log.Info().Msg("Starting the Cmd")

// Start the Cmd
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Fatal(err, "manager exited non-zero")
log.Fatal().
Err(err).
Msg("manager exited non-zero")
}
}
36 changes: 19 additions & 17 deletions pkg/controller/pravegacluster/pravegacluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
pravegav1beta1 "github.com/pravega/pravega-operator/pkg/apis/pravega/v1beta1"
"github.com/pravega/pravega-operator/pkg/controller/pravega"
"github.com/pravega/pravega-operator/pkg/util"
"github.com/rs/zerolog"
log "github.com/rs/zerolog/log"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
Expand All @@ -35,8 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

log "github.com/sirupsen/logrus"
)

// ReconcileTime is the delay between reconciliations
Expand All @@ -56,6 +56,8 @@ func newReconciler(mgr manager.Manager) reconcile.Reconciler {
// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Create a new controller
zerolog.SetGlobalLevel(util.LogLevel())

c, err := controller.New("pravegacluster-controller", mgr, controller.Options{Reconciler: r})
if err != nil {
return err
Expand Down Expand Up @@ -86,7 +88,7 @@ type ReconcilePravegaCluster struct {
// The Controller will requeue the Request to be processed again if the returned error is non-nil or
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcilePravegaCluster) Reconcile(request reconcile.Request) (reconcile.Result, error) {
log.Printf("Reconciling PravegaCluster %s/%s\n", request.Namespace, request.Name)
log.Info().Msgf("Reconciling PravegaCluster %s", fmt.Sprintf("%s/%s", request.Namespace, request.Name))

// Fetch the PravegaCluster instance
pravegaCluster := &pravegav1beta1.PravegaCluster{}
Expand All @@ -96,28 +98,28 @@ func (r *ReconcilePravegaCluster) Reconcile(request reconcile.Request) (reconcil
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
log.Printf("PravegaCluster %s/%s not found. Ignoring since object must be deleted\n", request.Namespace, request.Name)
log.Info().Msgf("PravegaCluster %s not found. Ignoring since object must be deleted", fmt.Sprintf("%s/%s", request.Namespace, request.Name))
return reconcile.Result{}, nil
}
// Error reading the object - requeue the request.
log.Printf("failed to get PravegaCluster: %v", err)
log.Error().Err(err).Msg("failed to get PravegaCluster:")
return reconcile.Result{}, err
}

// Set default configuration for unspecified values
changed := pravegaCluster.WithDefaults()
if changed {
log.Printf("Setting default settings for pravega-cluster: %s", request.Name)
log.Info().Msgf("Setting default settings for pravega-cluster: %s", request.Name)
if err = r.client.Update(context.TODO(), pravegaCluster); err != nil {
log.Printf("Error applying defaults on Pravega Cluster %v", err)
log.Error().Err(err).Msg("Error applying defaults on Pravega Cluster :")
return reconcile.Result{}, err
}
return reconcile.Result{Requeue: true}, nil
}

err = r.run(pravegaCluster)
if err != nil {
log.Printf("failed to reconcile pravega cluster (%s): %v", pravegaCluster.Name, err)
log.Error().Err(err).Msgf("failed to reconcile pravega cluster (%s):", pravegaCluster.Name)
return reconcile.Result{}, err
}
return reconcile.Result{RequeueAfter: ReconcileTime}, nil
Expand Down Expand Up @@ -194,7 +196,7 @@ func (r *ReconcilePravegaCluster) reconcileFinalizers(p *pravegav1beta1.PravegaC
event := p.NewApplicationEvent("ZKMETA_CLEANUP_ERROR", "ZK Metadata Cleanup Failed", message, "Error")
pubErr := r.client.Create(context.TODO(), event)
if pubErr != nil {
log.Printf("Error publishing zk metadata cleanup failure event to k8s. %v", pubErr)
log.Info().Msgf("Error publishing zk metadata cleanup failure event to k8s. %v", pubErr)
}
return fmt.Errorf(message)
}
Expand Down Expand Up @@ -435,7 +437,7 @@ func (r *ReconcilePravegaCluster) reconcileSegmentStoreService(p *pravegav1beta1
return fmt.Errorf("failed to delete Segmentstore pod (%s) for 10 mins ", pod.Name)
}
err = r.client.Get(context.TODO(), types.NamespacedName{Name: service.Name, Namespace: p.Namespace}, pod)
log.Printf("waiting for %v pod to be deleted", pod.Name)
log.Info().Msgf("waiting for %v pod to be deleted", pod.Name)
}
start = time.Now()
err = r.client.Get(context.TODO(), types.NamespacedName{Name: service.Name, Namespace: p.Namespace}, pod)
Expand All @@ -444,7 +446,7 @@ func (r *ReconcilePravegaCluster) reconcileSegmentStoreService(p *pravegav1beta1
return fmt.Errorf("failed to get Segmentstore pod (%s) as ready for 10 mins ", pod.Name)
}
err = r.client.Get(context.TODO(), types.NamespacedName{Name: service.Name, Namespace: p.Namespace}, pod)
log.Printf("waiting for %v pod to be in ready state", pod.Name)
log.Info().Msgf("waiting for %v pod to be in ready state", pod.Name)
}
}
}
Expand All @@ -468,7 +470,7 @@ func (r *ReconcilePravegaCluster) cleanUpZookeeperMeta(p *pravegav1beta1.Pravega
func (r *ReconcilePravegaCluster) deployCluster(p *pravegav1beta1.PravegaCluster) (err error) {
err = r.deployController(p)
if err != nil {
log.Printf("failed to deploy controller: %v", err)
log.Error().Err(err).Msg("failed to deploy controller:")
return err
}

Expand All @@ -478,7 +480,7 @@ func (r *ReconcilePravegaCluster) deployCluster(p *pravegav1beta1.PravegaCluster

err = r.deploySegmentStore(p)
if err != nil {
log.Printf("failed to deploy segment store: %v", err)
log.Error().Err(err).Msg("failed to deploy segment store: ")
return err
}

Expand Down Expand Up @@ -513,7 +515,7 @@ func (r *ReconcilePravegaCluster) deleteSTS(p *pravegav1beta1.PravegaCluster) er
}
// delete sts, if found
r.client.Delete(context.TODO(), sts)
log.Printf("Deleted old SegmentStore STS %s", sts.Name)
log.Info().Msgf("Deleted old SegmentStore STS %s", sts.Name)
return nil
}

Expand Down Expand Up @@ -568,7 +570,7 @@ func (r *ReconcilePravegaCluster) deleteOldSegmentStoreIfExists(p *pravegav1beta
return fmt.Errorf("failed to get external service (%s): %v", svcName, err)
}
r.client.Delete(context.TODO(), extService)
log.Printf("Deleted old SegmentStore external service %s", extService)
log.Info().Msgf("Deleted old SegmentStore external service %s", extService)
}
}
return nil
Expand Down Expand Up @@ -608,7 +610,7 @@ func (r *ReconcilePravegaCluster) deploySegmentStore(p *pravegav1beta1.PravegaCl
}
owRefs := sts.GetOwnerReferences()
if hasOldVersionOwnerReference(owRefs) {
log.Printf("Deleting SSS STS as it has old version owner ref.")
log.Info().Msgf("Deleting SSS STS as it has old version owner ref.")
err = r.client.Delete(context.TODO(), sts)
if err != nil {
return err
Expand Down Expand Up @@ -931,7 +933,7 @@ func (r *ReconcilePravegaCluster) rollbackFailedUpgrade(p *pravegav1beta1.Praveg
if r.isRollbackTriggered(p) {
// start rollback to previous version
previousVersion := p.Status.GetLastVersion()
log.Printf("Rolling back to last cluster version %v", previousVersion)
log.Info().Msgf("Rolling back to last cluster version %v", previousVersion)
//Rollback cluster to previous version
return r.rollbackClusterVersion(p, previousVersion)
}
Expand Down
Loading