Skip to content

Commit

Permalink
Add the field version into knativeserving spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Hou committed May 27, 2020
1 parent d544f7c commit f912ec1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
3 changes: 3 additions & 0 deletions config/300-serving.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ spec:
spec:
description: Spec defines the desired state of KnativeServing
properties:
version:
description: The version of Knative Serving to be installed
type: string
config:
additionalProperties:
additionalProperties:
Expand Down
34 changes: 16 additions & 18 deletions pkg/reconciler/knativeserving/knativeserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"path/filepath"
"github.com/go-logr/zapr"

mf "github.com/manifestival/manifestival"
Expand Down Expand Up @@ -99,14 +99,18 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, original *servingv1alpha1
// converge the two.
func (r *Reconciler) ReconcileKind(ctx context.Context, ks *servingv1alpha1.KnativeServing) pkgreconciler.Event {
logger := logging.FromContext(ctx)
// Read the old version of the Knative Serving and the version of Knative Serving to be installed
oldVerion, newVersion := r.retrieveVersions(ks)
if newVersion == "" {
logger.Info("No version is specified in Knative Serving CR.")
return nil
}

ks.Status.InitializeConditions()
ks.Status.ObservedGeneration = ks.Generation

logger.Infow("Reconciling KnativeServing", "status", ks.Status)

// Read the old version of the Knative Serving and the version of Knative Serving to be installed
oldVerion, newVersion := r.retrieveVersions(ks)

// Get the Serving Manifest to be installed
servingManifest, err := r.retrieveManifest(ctx, newVersion)
if err != nil {
Expand Down Expand Up @@ -188,11 +192,7 @@ func (r *Reconciler) transform(ctx context.Context, instance *servingv1alpha1.Kn
func (r *Reconciler) install(ctx context.Context, manifest *mf.Manifest, instance *servingv1alpha1.KnativeServing) error {
logger := logging.FromContext(ctx)
logger.Debug("Installing manifest")
version := version.ServingVersion
if instance.Spec.GetVersion() != "" {
version = instance.Spec.GetVersion()
}
return common.Install(manifest, version, &instance.Status)
return common.Install(manifest, instance.Spec.GetVersion(), &instance.Status)
}

// Check for all deployments available
Expand Down Expand Up @@ -228,7 +228,7 @@ func (r *Reconciler) deleteObsoleteResources(ctx context.Context, manifest *mf.M
return nil
}

func (r *Reconciler) retrieveManifest(ctx context.Context, version string) (mf.Manifest, error){
func (r *Reconciler) retrieveManifest(ctx context.Context, version string) (mf.Manifest, error) {
if val, found := r.manifests[version]; found {
return val, nil
}
Expand All @@ -248,16 +248,14 @@ func (r *Reconciler) retrieveManifest(ctx context.Context, version string) (mf.M
return manifest, nil
}

func (r *Reconciler) retrieveVersions(instance *servingv1alpha1.KnativeServing) (string, string){
oldVersion := version.ServingVersion
newVersion := version.ServingVersion
if instance.Status.GetVersion() != "" {
oldVersion = instance.Status.GetVersion()
} else if instance.Spec.GetVersion() != "" {
oldVersion = instance.Spec.GetVersion()
}
func (r *Reconciler) retrieveVersions(instance *servingv1alpha1.KnativeServing) (string, string) {
newVersion := ""
if instance.Spec.GetVersion() != "" {
newVersion = instance.Spec.GetVersion()
}
oldVersion := newVersion
if instance.Status.GetVersion() != "" {
oldVersion = instance.Status.GetVersion()
}
return oldVersion, newVersion
}

0 comments on commit f912ec1

Please sign in to comment.