Skip to content

Commit

Permalink
Merge branch 'main' into less-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Starefossen authored Jan 22, 2024
2 parents 4c52849 + 5bc9a34 commit 79c5191
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
6 changes: 3 additions & 3 deletions controllers/apitoken_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type ApiTokenReconciler struct {
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/reconcile
func (r *ApiTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("apitoken")

log.Info("Starting reconciliation of ApiToken")
token := &unleashv1.ApiToken{}
Expand Down Expand Up @@ -321,7 +321,7 @@ func (r *ApiTokenReconciler) getUnleashInstance(ctx context.Context, token *unle

// updateStatusSuccess will set the status condition as created and reset the failed status condition
func (r *ApiTokenReconciler) updateStatusSuccess(ctx context.Context, apiToken *unleashv1.ApiToken) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("apitoken")
log.Info("Successfully created ApiToken")

apiTokenStatus.WithLabelValues(apiToken.Namespace, apiToken.Name, unleashv1.ApiTokenStatusConditionTypeCreated).Set(1.0)
Expand Down Expand Up @@ -354,7 +354,7 @@ func (r *ApiTokenReconciler) updateStatusSuccess(ctx context.Context, apiToken *

// updateStatusFailed will set the status condition as failed, but not reset the created status condition
func (r *ApiTokenReconciler) updateStatusFailed(ctx context.Context, apiToken *unleashv1.ApiToken, err error, reason, message string) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("apitoken")

if err != nil {
log.Error(err, fmt.Sprintf("%s for ApiToken", message))
Expand Down
14 changes: 7 additions & 7 deletions controllers/remoteunleash_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type RemoteUnleashFederation struct {
//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete

func (r *RemoteUnleashReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("remoteunleash")

log.Info("Starting reconciliation of RemoteUnleash")
remoteUnleash := &unleashv1.RemoteUnleash{}
Expand Down Expand Up @@ -242,7 +242,7 @@ func (r *RemoteUnleashReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

func (r *RemoteUnleashReconciler) updateStatusConnectionSuccess(ctx context.Context, stats *unleashclient.InstanceAdminStatsResult, remoteUnleash *unleashv1.RemoteUnleash) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("remoteunleash")

log.Info("Successfully connected to Unleash")
return r.updateStatus(ctx, remoteUnleash, stats, metav1.Condition{
Expand All @@ -254,7 +254,7 @@ func (r *RemoteUnleashReconciler) updateStatusConnectionSuccess(ctx context.Cont
}

func (r *RemoteUnleashReconciler) updateStatusConnectionFailed(ctx context.Context, remoteUnleash *unleashv1.RemoteUnleash, stats *unleashclient.InstanceAdminStatsResult, err error, message string) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("remoteunleash")

log.Error(err, fmt.Sprintf("%s for Unleash", message))
return r.updateStatus(ctx, remoteUnleash, stats, metav1.Condition{
Expand All @@ -266,7 +266,7 @@ func (r *RemoteUnleashReconciler) updateStatusConnectionFailed(ctx context.Conte
}

func (r *RemoteUnleashReconciler) updateStatusReconcileSuccess(ctx context.Context, remoteUnleash *unleashv1.RemoteUnleash, stats *unleashclient.InstanceAdminStatsResult) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("remoteunleash")

log.Info("Successfully reconciled RemoteUnleash")
return r.updateStatus(ctx, remoteUnleash, stats, metav1.Condition{
Expand All @@ -278,7 +278,7 @@ func (r *RemoteUnleashReconciler) updateStatusReconcileSuccess(ctx context.Conte
}

func (r *RemoteUnleashReconciler) updateStatusReconcileFailed(ctx context.Context, remoteUnleash *unleashv1.RemoteUnleash, stats *unleashclient.InstanceAdminStatsResult, err error, message string) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("remoteunleash")

log.Error(err, fmt.Sprintf("%s for RemoteUnleash", message))
return r.updateStatus(ctx, remoteUnleash, stats, metav1.Condition{
Expand All @@ -290,7 +290,7 @@ func (r *RemoteUnleashReconciler) updateStatusReconcileFailed(ctx context.Contex
}

func (r *RemoteUnleashReconciler) updateStatus(ctx context.Context, remoteUnleash *unleashv1.RemoteUnleash, stats *unleashclient.InstanceAdminStatsResult, status metav1.Condition) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("remoteunleash")

if err := r.Get(ctx, remoteUnleash.NamespacedName(), remoteUnleash); err != nil {
log.Error(err, "Failed to get RemoteUnleash")
Expand Down Expand Up @@ -329,7 +329,7 @@ func (r *RemoteUnleashReconciler) doFinalizerOperationsForToken(remoteUnleash *u
}

func (r *RemoteUnleashReconciler) FederationSubscribe(ctx context.Context) error {
log := log.FromContext(ctx).WithName("FederationSubscribe")
log := log.FromContext(ctx).WithName("subscribe")

if !r.Federation.Enabled {
log.Info("Federation is disabled, not consuming pubsub messages")
Expand Down
21 changes: 10 additions & 11 deletions controllers/unleash_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ type UnleashFederation struct {
//+kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors,verbs=get;list;watch;create;update;patch;delete

func (r *UnleashReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

log := log.FromContext(ctx).WithName("unleash")
log.Info("Starting reconciliation of Unleash")

unleash := &unleashv1.Unleash{}
Expand Down Expand Up @@ -366,7 +365,7 @@ func (r *UnleashReconciler) doFinalizerOperationsForUnleash(cr *unleashv1.Unleas

// reconcileServiceMonitor will ensure that the required ServiceMonitor is created
func (r *UnleashReconciler) reconcileServiceMonitor(ctx context.Context, unleash *unleashv1.Unleash) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

newServiceMonitor, err := resources.ServiceMonitorForUnleash(unleash, r.Scheme)
if err != nil {
Expand Down Expand Up @@ -421,7 +420,7 @@ func (r *UnleashReconciler) reconcileServiceMonitor(ctx context.Context, unleash

// reconcileNetworkPolicy will ensure that the required network policy is created
func (r *UnleashReconciler) reconcileNetworkPolicy(ctx context.Context, unleash *unleashv1.Unleash) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

newNetPol, err := resources.NetworkPolicyForUnleash(unleash, r.Scheme, r.OperatorNamespace)
if err != nil {
Expand Down Expand Up @@ -479,7 +478,7 @@ func (r *UnleashReconciler) reconcileNetworkPolicy(ctx context.Context, unleash

// reconcileIngress will ensure that the required ingress is created
func (r *UnleashReconciler) reconcileIngress(ctx context.Context, unleash *unleashv1.Unleash, ingress *unleashv1.UnleashIngressConfig, nameSuffix string) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

newIngress, err := resources.IngressForUnleash(unleash, ingress, nameSuffix, r.Scheme)
if err != nil {
Expand Down Expand Up @@ -552,7 +551,7 @@ func (r *UnleashReconciler) reconcileIngresses(ctx context.Context, unleash *unl

// reconcileSecrets will ensure that the required secrets are created
func (r *UnleashReconciler) reconcileSecrets(ctx context.Context, unleash *unleashv1.Unleash) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

// Check if operator secret already exists, if not create a new one
operatorSecret := &corev1.Secret{}
Expand Down Expand Up @@ -603,7 +602,7 @@ func (r *UnleashReconciler) reconcileSecrets(ctx context.Context, unleash *unlea

// reconcileDeployment will ensure that the required deployment is created
func (r *UnleashReconciler) reconcileDeployment(ctx context.Context, unleash *unleashv1.Unleash) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

dep, err := resources.DeploymentForUnleash(unleash, r.Scheme)
if err != nil {
Expand Down Expand Up @@ -641,7 +640,7 @@ func (r *UnleashReconciler) reconcileDeployment(ctx context.Context, unleash *un

// reconcileService will ensure that the Service for the Unleash instance is created
func (r *UnleashReconciler) reconcileService(ctx context.Context, unleash *unleashv1.Unleash) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

newSvc, err := resources.ServiceForUnleash(unleash, r.Scheme)
if err != nil {
Expand Down Expand Up @@ -710,7 +709,7 @@ func (r *UnleashReconciler) updateStatusReconcileSuccess(ctx context.Context, un
}

func (r *UnleashReconciler) updateStatusReconcileFailed(ctx context.Context, unleash *unleashv1.Unleash, err error, message string) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

if verr, ok := err.(*resources.ValidationError); ok {
message = fmt.Sprintf("%s: %s", message, verr.Error())
Expand All @@ -735,7 +734,7 @@ func (r *UnleashReconciler) updateStatusConnectionSuccess(ctx context.Context, u
}

func (r *UnleashReconciler) updateStatusConnectionFailed(ctx context.Context, unleash *unleashv1.Unleash, err error, message string) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

log.Error(err, fmt.Sprintf("%s for Unleash", message))
return r.updateStatus(ctx, unleash, nil, metav1.Condition{
Expand All @@ -747,7 +746,7 @@ func (r *UnleashReconciler) updateStatusConnectionFailed(ctx context.Context, un
}

func (r *UnleashReconciler) updateStatus(ctx context.Context, unleash *unleashv1.Unleash, stats *unleashclient.InstanceAdminStatsResult, status metav1.Condition) error {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("unleash")

switch status.Type {
case unleashv1.UnleashStatusConditionTypeReconciled:
Expand Down
2 changes: 1 addition & 1 deletion pkg/federation/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p *publisher) Close() error {
// Publish publishes the given Unleash instance to the federation topic using the provided API token.
// Returns an error if the message could not be published.
func (p *publisher) Publish(ctx context.Context, unleash *unleashv1.Unleash, apiToken string) error {
log := log.FromContext(ctx).WithName("publisher")
log := log.FromContext(ctx).WithName("publish")

instance := UnleashFederationInstance(unleash, apiToken)
payload, err := proto.Marshal(instance)
Expand Down

0 comments on commit 79c5191

Please sign in to comment.