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

Install the manifest based on the version specified in knativeserving spec #102

Closed
wants to merge 15 commits into from

Conversation

houshengbo
Copy link
Contributor

@houshengbo houshengbo commented May 26, 2020

Fixes #56
We can use the following CR to install knative serving 0.15.0.

apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
  name: knative-serving
  namespace: knative-serving
spec:
  version: 0.15.0

Proposed Changes

  • This PR bundles two versions of Knative Serving 0.14.0 and 0.15.0.
  • User can specify the version with knativeserving CRD spec.version.
  • Knative serving can upgrade from 0.14.0 to 0.15.0 and downgrade from 0.15.0 to 0.14.0.
  • If no version is specified, the default version is taken. The default version is retrieved by reading the names of the directories under kodata/knative-serving.

Release Note


@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: houshengbo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label May 26, 2020
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 26, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@houshengbo: 0 warnings.

In response to this:

Fixes #

Proposed Changes

Release Note


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo force-pushed the load-manifest-version branch from 9002e46 to d544f7c Compare May 26, 2020 21:40
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo changed the title Load manifest version Install the manifest based on the version specified in knativeserving spec May 26, 2020
@houshengbo houshengbo changed the title Install the manifest based on the version specified in knativeserving spec WIP: Install the manifest based on the version specified in knativeserving spec May 26, 2020
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 26, 2020
@houshengbo houshengbo force-pushed the load-manifest-version branch from c2c06f8 to fc90c53 Compare May 26, 2020 22:00
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo force-pushed the load-manifest-version branch 2 times, most recently from 8fd24dd to 8dac9b7 Compare May 27, 2020 02:55
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo force-pushed the load-manifest-version branch from 8dac9b7 to f912ec1 Compare May 27, 2020 03:05
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

if err != nil {
ks.Status.MarkInstallFailed(err.Error())
return err
}

// Find the common resources between the old and the current serving manifests
manifestApply := servingManifest.Filter(mf.In(oldManifest))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably shouldn't filter at all or we'll never create new resources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, don't filter this at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@jcrossley3 jcrossley3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make the logic in here more clear.

Comment on lines 85 to 87
} else if len(servingManifest.Resources()) == 0 {
return fmt.Errorf("unable to find the manifest for the Knative Serving version %s", version.ServingVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You perform this check every time you call retrieveManifest. Therefore, move this check into retrieveManifest and you can eliminate all the "else if..." in the callers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -87,34 +99,76 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needlessly confusing. Instead of retrieveVersions how about two functions:

func (r *Reconciler) getTarget(ctx context.Context, instance *servingv1alpha1.KnativeServing) (mf.Manifest, error) {...}
func (r *Reconciler) getCurrent(ctx context.Context, instance *servingv1alpha1.KnativeServing) (mf.Manifest, error) {...}

Encapsulate the logic of determining the proper version within each, including applying the appropriate transforms. The first function may, in fact, use status.version if spec.version is nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is much more convenient to have two functions, wrapping the logic to verify the versions.

Comment on lines 118 to 105
} else if len(servingManifest.Resources()) == 0 {
return fmt.Errorf("unable to find the manifest for the Knative Serving version %s", newVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ibid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 126 to 111
} else if len(oldManifest.Resources()) == 0 {
return fmt.Errorf("unable to find the previous manifest for the Knative Serving version %s", oldVerion)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ibid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 136 to 138
deleteStages := []func(context.Context, *mf.Manifest, *servingv1alpha1.KnativeServing) error{
r.deleteObsoleteResources,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary. We don't even need deleteObsoleteResources anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 160 to 128
for _, stage := range deleteStages {
if err := stage(ctx, &manifestDelete, ks); err != nil {
return err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be the following...

if err := oldManifest.Filter(mf.None(mf.In(servingManifest))).Delete(); err != nil {
	return err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if err != nil {
ks.Status.MarkInstallFailed(err.Error())
return err
}

// Find the common resources between the old and the current serving manifests
manifestApply := servingManifest.Filter(mf.In(oldManifest))
manifestDelete := servingManifest.Filter(mf.None(mf.In(oldManifest)))
Copy link
Contributor

@jcrossley3 jcrossley3 May 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is backwards. Remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

logger.Infow("Reconcile stages complete", "status", ks.Status)
return nil
}

// Transform the resources
func (r *Reconciler) transform(ctx context.Context, instance *servingv1alpha1.KnativeServing) (mf.Manifest, error) {
func (r *Reconciler) transform(ctx context.Context, instance *servingv1alpha1.KnativeServing, servingManifest mf.Manifest) (mf.Manifest, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird to pass a manifest only to transform it. Let's have transform return a []Transformer and let the caller deal with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return manifest, nil
}

func (r *Reconciler) retrieveVersions(instance *servingv1alpha1.KnativeServing) (string, string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to force callers to deal with the possible empty versions strings here. I'd recommend a more "intentional" approach: a function to return the manifest i need, a function to return the manifest i have. Make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is removed.

@houshengbo houshengbo force-pushed the load-manifest-version branch from f912ec1 to 54e0d5f Compare May 27, 2020 21:55
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo force-pushed the load-manifest-version branch 2 times, most recently from 0543b87 to f86b0fd Compare May 28, 2020 13:46
@@ -74,7 +77,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, original *servingv1alpha1
}
}

manifest, err := r.transform(ctx, original)
manifest, err := r.getCurrentManifest(ctx, original)
if err != nil {
return fmt.Errorf("failed to transform manifest: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd just return err here, as "transform" isn't exactly accurate, as long as you ensure proper errors are returned from getCurrentManifest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

return err
}
}

// Remove the resources, that does not exist in the new Serving manifest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Remove the resources, that does not exist in the new Serving manifest
// Remove the resources that do not exist in the new Serving manifest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}

// Apply the manifest resources
func (r *Reconciler) install(ctx context.Context, manifest *mf.Manifest, instance *servingv1alpha1.KnativeServing) error {
logger := logging.FromContext(ctx)
logger.Debug("Installing manifest")
return common.Install(manifest, version.ServingVersion, &instance.Status)
return common.Install(manifest, instance.Spec.GetVersion(), &instance.Status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can instance.Spec.GetVersion() return "" here? Should the operator set it if the user doesn't? Will common.Install handle "" predictably?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I need to makes sure there is a valid version.

manifest, found := r.manifests[version]
if !found {
koDataDir := os.Getenv("KO_DATA_PATH")
manifesrDir := fmt.Sprintf("knative-serving/%s", version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
manifesrDir := fmt.Sprintf("knative-serving/%s", version)
manifestDir := fmt.Sprintf("knative-serving/%s", version)

Comment on lines 205 to 214
// Transform the manifest
transformers, err := r.transform(ctx, instance)
if err != nil {
return mf.Manifest{}, err
}

manifestTransformed, err := manifest.Transform(transformers...)
if err != nil {
return mf.Manifest{}, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not committed yet?

logger := logging.FromContext(ctx)
var err error
manifest, found := r.manifests[version]
if !found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should really be in common since eventing will need it, too. At which point, you can delete version/version.go

"path/filepath"
"runtime"
"testing"

mf "github.com/manifestival/manifestival"
"knative.dev/operator/pkg/reconciler/common"
)

func TestManifestVersionServingSame(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get rid of this file entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo force-pushed the load-manifest-version branch from 790f21a to 7746d6b Compare May 28, 2020 22:28
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@houshengbo houshengbo force-pushed the load-manifest-version branch 2 times, most recently from ccda62b to 23054ab Compare May 28, 2020 22:43
@jcrossley3
Copy link
Contributor

/hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 28, 2020
@houshengbo houshengbo force-pushed the load-manifest-version branch from 23054ab to fdf4380 Compare May 29, 2020 01:15
@knative-prow-robot
Copy link
Contributor

@houshengbo: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-knative-operator-go-coverage fdf4380 link /test pull-knative-operator-go-coverage
pull-knative-operator-integration-tests fdf4380 link /test pull-knative-operator-integration-tests
pull-knative-operator-upgrade-tests fdf4380 link /test pull-knative-operator-upgrade-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@houshengbo
Copy link
Contributor Author

This PR points to the direction of how spec.version is implemented.
I will start to break it into separate PRs.
Also, some foundational PRs will be opened to refactor the test cases and test scripts.
@jcrossley3 @markusthoemmes @evankanderson

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 2, 2020
@knative-prow-robot
Copy link
Contributor

@houshengbo: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@houshengbo houshengbo closed this Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support decoupling operator and installed software versions
6 participants