Skip to content

Commit

Permalink
Merge pull request #17 from pb82/compare-resources
Browse files Browse the repository at this point in the history
Compare resources
  • Loading branch information
pb82 authored Jun 22, 2019
2 parents 03367f3 + 37a9e8f commit cd0eb5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/integreatly/v1alpha1/grafanadatasource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type GrafanaDataSourceSpec struct {
// GrafanaDataSourceStatus defines the observed state of GrafanaDataSource
// +k8s:openapi-gen=true
type GrafanaDataSourceStatus struct {
Phase int `json:"phase"`
Phase int `json:"phase"`
LastConfig string `json:"lastConfig"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
16 changes: 15 additions & 1 deletion pkg/controller/grafanadatasource/datasource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grafanadatasource

import (
"context"
"crypto/md5"
"fmt"
i8ly "github.com/integr8ly/grafana-operator/pkg/apis/integreatly/v1alpha1"
"github.com/integr8ly/grafana-operator/pkg/controller/common"
Expand Down Expand Up @@ -115,6 +116,14 @@ func (r *ReconcileGrafanaDataSource) reconcileDatasource(cr *i8ly.GrafanaDataSou
return reconcile.Result{}, err
}

changed, hash := r.hasDatasourceChanged(ds, cr)
if !changed {
log.Info("data source reconciled but no changes")
return reconcile.Result{}, nil
}

cr.Status.LastConfig = hash

updated, err := r.helper.UpdateDataSources(cr.Spec.Name, cr.Namespace, ds)
if err != nil {
return reconcile.Result{}, err
Expand All @@ -130,7 +139,12 @@ func (r *ReconcileGrafanaDataSource) reconcileDatasource(cr *i8ly.GrafanaDataSou
}

log.Info(fmt.Sprintf("datasource '%s' updated", cr.Spec.Name))
return reconcile.Result{}, err
return r.updatePhase(cr, common.StatusResourceCreated)
}

func (r *ReconcileGrafanaDataSource) hasDatasourceChanged(newConfig string, cr *i8ly.GrafanaDataSource) (bool, string) {
hash := fmt.Sprintf("%x", md5.Sum([]byte(newConfig)))
return hash != cr.Status.LastConfig, hash
}

func (r *ReconcileGrafanaDataSource) DeleteDatasource(cr *i8ly.GrafanaDataSource) (reconcile.Result, error) {
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package version

var (
Version = "1.1.0"
Version = "1.1.1"
)

0 comments on commit cd0eb5a

Please sign in to comment.