-
Notifications
You must be signed in to change notification settings - Fork 101
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
Conversation
[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 |
There was a problem hiding this 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.
There was a problem hiding this 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)
9002e46
to
d544f7c
Compare
There was a problem hiding this 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)
There was a problem hiding this 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)
c2c06f8
to
fc90c53
Compare
There was a problem hiding this 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)
8fd24dd
to
8dac9b7
Compare
There was a problem hiding this 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)
There was a problem hiding this 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)
8dac9b7
to
f912ec1
Compare
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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.
} else if len(servingManifest.Resources()) == 0 { | ||
return fmt.Errorf("unable to find the manifest for the Knative Serving version %s", version.ServingVersion) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
} else if len(servingManifest.Resources()) == 0 { | ||
return fmt.Errorf("unable to find the manifest for the Knative Serving version %s", newVersion) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ibid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} else if len(oldManifest.Resources()) == 0 { | ||
return fmt.Errorf("unable to find the previous manifest for the Knative Serving version %s", oldVerion) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ibid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
deleteStages := []func(context.Context, *mf.Manifest, *servingv1alpha1.KnativeServing) error{ | ||
r.deleteObsoleteResources, | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
for _, stage := range deleteStages { | ||
if err := stage(ctx, &manifestDelete, ks); err != nil { | ||
return err | ||
} | ||
} |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is removed.
f912ec1
to
54e0d5f
Compare
There was a problem hiding this 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)
There was a problem hiding this 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)
There was a problem hiding this 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)
0543b87
to
f86b0fd
Compare
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Remove the resources, that does not exist in the new Serving manifest | |
// Remove the resources that do not exist in the new Serving manifest |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manifesrDir := fmt.Sprintf("knative-serving/%s", version) | |
manifestDir := fmt.Sprintf("knative-serving/%s", version) |
// 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 | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
version/version_test.go
Outdated
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
mf "github.com/manifestival/manifestival" | ||
"knative.dev/operator/pkg/reconciler/common" | ||
) | ||
|
||
func TestManifestVersionServingSame(t *testing.T) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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)
There was a problem hiding this 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)
790f21a
to
7746d6b
Compare
There was a problem hiding this 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)
There was a problem hiding this 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)
There was a problem hiding this 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)
There was a problem hiding this 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)
ccda62b
to
23054ab
Compare
/hold |
23054ab
to
fdf4380
Compare
@houshengbo: The following tests failed, say
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. |
This PR points to the direction of how |
@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. |
Fixes #56
We can use the following CR to install knative serving 0.15.0.
Proposed Changes
Release Note