Skip to content

Commit

Permalink
Diff both spec and meta in routes and configs in service reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Gu committed Jan 16, 2020
1 parent 78953ad commit 97ca0e3
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions pkg/reconciler/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,34 @@ func (c *Reconciler) reconcileConfiguration(ctx context.Context, service *v1alph
// In the case of an upgrade, there can be default values set that don't exist pre-upgrade.
// We are setting the up-to-date default values here so an update won't be triggered if the only
// diff is the new default values.
config.SetDefaults(ctx)
existing.SetDefaults(ctx)

desiredConfig, err := resources.MakeConfiguration(service)
if err != nil {
return nil, err
}

if configSemanticEquals(desiredConfig, config) {
if configSemanticEquals(desiredConfig, existing) {
// No differences to reconcile.
return config, nil
}
diff, err := kmp.SafeDiff(desiredConfig.Spec, config.Spec)

diffSpec, err := kmp.SafeDiff(desiredConfig.Spec, existing.Spec)
if err != nil {
return nil, fmt.Errorf("failed to diff Configuration spec: %w", err)
}
diffLabels, err := kmp.SafeDiff(desiredConfig.ObjectMeta.Labels, existing.ObjectMeta.Labels)
if err != nil {
return nil, fmt.Errorf("failed to diff Configuration meta labels: %w", err)
}
diffAnnos, err := kmp.SafeDiff(desiredConfig.ObjectMeta.Annotations, existing.ObjectMeta.Annotations)
if err != nil {
return nil, fmt.Errorf("failed to diff Configuration: %w", err)
return nil, fmt.Errorf("failed to diff Configuration meta annotations: %w", err)
}
logger.Infof("Reconciling configuration diff (-desired, +observed): %s", diff)
if diff == "" {
logger.Infof("Reconciling configuration spec diff (-desired, +observed): %s", diffSpec)
logger.Infof("Reconciling configuration meta labels diff (-desired, +observed): %s", diffLabels)
logger.Infof("Reconciling configuration meta annotations diff (-desired, +observed): %s", diffAnnos)
if diffSpec == "" && diffLabels == "" && diffAnnos == "" {
// No differences to reconcile.
return config, nil
}
Expand Down Expand Up @@ -372,7 +383,7 @@ func (c *Reconciler) reconcileRoute(ctx context.Context, service *v1alpha1.Servi
// In the case of an upgrade, there can be default values set that don't exist pre-upgrade.
// We are setting the up-to-date default values here so an update won't be triggered if the only
// diff is the new default values.
route.SetDefaults(ctx)
existing.SetDefaults(ctx)
desiredRoute, err := resources.MakeRoute(service)
if err != nil {
// This should be unreachable as configuration creation
Expand All @@ -381,16 +392,26 @@ func (c *Reconciler) reconcileRoute(ctx context.Context, service *v1alpha1.Servi
return nil, err
}

if routeSemanticEquals(desiredRoute, route) {
if routeSemanticEquals(desiredRoute, existing) {
// No differences to reconcile.
return route, nil
}
diff, err := kmp.SafeDiff(desiredRoute.Spec, route.Spec)
diffSpec, err := kmp.SafeDiff(desiredRoute.Spec, existing.Spec)
if err != nil {
return nil, fmt.Errorf("failed to diff Route spec: %w", err)
}
diffLabels, err := kmp.SafeDiff(desiredRoute.ObjectMeta.Labels, existing.ObjectMeta.Labels)
if err != nil {
return nil, fmt.Errorf("failed to diff Route meta labels: %w", err)
}
diffAnnos, err := kmp.SafeDiff(desiredRoute.ObjectMeta.Annotations, existing.ObjectMeta.Annotations)
if err != nil {
return nil, fmt.Errorf("failed to diff Route: %w", err)
return nil, fmt.Errorf("failed to diff Route meta annotations: %w", err)
}
logger.Infof("Reconciling route diff (-desired, +observed): %s", diff)
if diff == "" {
logger.Infof("Reconciling route spec diff (-desired, +observed): %s", diffSpec)
logger.Infof("Reconciling route meta labels diff (-desired, +observed): %s", diffLabels)
logger.Infof("Reconciling route meta annotations diff (-desired, +observed): %s", diffAnnos)
if diffSpec == "" && diffLabels == "" && diffAnnos == "" {
// No differences to reconcile.
return route, nil
}
Expand Down

0 comments on commit 97ca0e3

Please sign in to comment.