-
Notifications
You must be signed in to change notification settings - Fork 116
Change file structure for ingresses #1355
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
Changes from 3 commits
0b7296d
b8b3331
3c11c53
746807c
2d866bf
01acb99
bd4de72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,51 +24,13 @@ import ( | |
|
|
||
| mf "github.com/manifestival/manifestival" | ||
| "golang.org/x/mod/semver" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "knative.dev/operator/pkg/apis/operator/base" | ||
| "knative.dev/operator/pkg/apis/operator/v1beta1" | ||
| "knative.dev/operator/pkg/reconciler/common" | ||
| ) | ||
|
|
||
| const providerLabel = "networking.knative.dev/ingress-provider" | ||
|
|
||
| func ingressFilter(name string) mf.Predicate { | ||
| return func(u *unstructured.Unstructured) bool { | ||
| provider, hasLabel := u.GetLabels()[providerLabel] | ||
| if !hasLabel { | ||
| return true | ||
| } | ||
| return provider == name | ||
| } | ||
| } | ||
|
|
||
| // noneFilter drops all ingresses but allows everything else. | ||
| func noneFilter(u *unstructured.Unstructured) bool { | ||
| _, hasLabel := u.GetLabels()[providerLabel] | ||
| return !hasLabel | ||
| } | ||
|
|
||
| // Filters makes sure the disabled ingress resources are removed from the manifest. | ||
| func Filters(ks *v1beta1.KnativeServing) mf.Predicate { | ||
| var filters []mf.Predicate | ||
| if ks.Spec.Ingress == nil { | ||
| return istioFilter | ||
| } | ||
| if ks.Spec.Ingress.Istio.Enabled { | ||
| filters = append(filters, istioFilter) | ||
| } | ||
| if ks.Spec.Ingress.Kourier.Enabled { | ||
| filters = append(filters, kourierFilter) | ||
| } | ||
| if ks.Spec.Ingress.Contour.Enabled { | ||
| filters = append(filters, contourFilter) | ||
| } | ||
| if len(filters) == 0 { | ||
| return noneFilter | ||
| } | ||
| return mf.Any(filters...) | ||
| } | ||
|
|
||
| // Transformers returns a list of transformers based on the enabled ingresses | ||
| func Transformers(ctx context.Context, ks *v1beta1.KnativeServing) []mf.Transformer { | ||
| if ks.Spec.Ingress == nil { | ||
|
|
@@ -87,61 +49,90 @@ func Transformers(ctx context.Context, ks *v1beta1.KnativeServing) []mf.Transfor | |
| return transformers | ||
| } | ||
|
|
||
| func getIngress(version string) (mf.Manifest, error) { | ||
| // If we can not determine the version, append no ingress manifest. | ||
| if version == "" { | ||
| func getIngress(path string) (mf.Manifest, error) { | ||
| if path == "" { | ||
| return mf.Manifest{}, nil | ||
| } | ||
| return common.FetchManifest(path) | ||
| } | ||
|
|
||
| func getIngressPath(version string, ks *v1beta1.KnativeServing) string { | ||
| var urls []string | ||
| koDataDir := os.Getenv(common.KoEnvKey) | ||
| // Ingresses are saved in the directory named major.minor. We remove the patch number. | ||
| ingressVersion := common.LATEST_VERSION | ||
| sourceVersion := common.LATEST_VERSION | ||
| if !strings.EqualFold(version, common.LATEST_VERSION) { | ||
| ingressVersion = semver.MajorMinor(common.SanitizeSemver(version))[1:] | ||
| sourceVersion = semver.MajorMinor(common.SanitizeSemver(version))[1:] | ||
| } | ||
|
|
||
| // This line can make sure a valid available source version is returned. | ||
| ingressPath := filepath.Join(koDataDir, "ingress", sourceVersion) | ||
| if ks.Spec.Ingress == nil { | ||
| url := filepath.Join(ingressPath, "istio") | ||
| urls = append(urls, url) | ||
| return strings.Join(urls, common.COMMA) | ||
| } | ||
|
|
||
| if ks.Spec.Ingress.Istio.Enabled { | ||
| url := filepath.Join(ingressPath, "istio") | ||
| urls = append(urls, url) | ||
| } | ||
| if ks.Spec.Ingress.Contour.Enabled { | ||
| url := filepath.Join(ingressPath, "contour") | ||
| urls = append(urls, url) | ||
| } | ||
| if ks.Spec.Ingress.Kourier.Enabled { | ||
| url := filepath.Join(ingressPath, "kourier") | ||
| urls = append(urls, url) | ||
| } | ||
|
|
||
| // This line can make sure a valid available ingress version is returned. | ||
| ingressVersion = common.GetLatestIngressRelease(ingressVersion) | ||
| ingressPath := filepath.Join(koDataDir, "ingress", ingressVersion) | ||
| return common.FetchManifest(ingressPath) | ||
| if len(urls) == 0 { | ||
| url := filepath.Join(ingressPath, "istio") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have the default behavior around L#67 so it should be fine, I think. But currently (without this PR)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Let me change it. I can add some more test cases to see if the edge cases are covered. |
||
| urls = append(urls, url) | ||
| } | ||
|
|
||
| return strings.Join(urls, common.COMMA) | ||
| } | ||
|
|
||
| // AppendTargetIngresses appends the manifests of ingresses to be installed | ||
| func AppendTargetIngresses(ctx context.Context, manifest *mf.Manifest, instance base.KComponent) error { | ||
| m, err := getIngress(common.TargetVersion(instance)) | ||
| // AppendTargetIngress appends the manifests of the ingress to be installed | ||
| func AppendTargetIngress(ctx context.Context, manifest *mf.Manifest, instance base.KComponent) error { | ||
| version := common.TargetVersion(instance) | ||
| ingressPath := getIngressPath(version, convertToKS(instance)) | ||
| m, err := getIngress(ingressPath) | ||
| if err == nil { | ||
| *manifest = manifest.Append(m) | ||
| } | ||
|
|
||
| if len(instance.GetSpec().GetManifests()) != 0 { | ||
| // If spec.manifests is not empty, it is possible that the ingress is not available with the specified version. | ||
| // The user can specify the ingress link in the spec.manifests. | ||
| // If spec.manifests is not empty, it is possible that the eventing source is not available with the | ||
| // specified version. The user can specify the eventing source link in the spec.manifests. | ||
| return nil | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| // AppendInstalledIngresses appends the installed manifests of ingresses | ||
| // AppendInstalledIngresses appends all the manifests of the ingresses | ||
| func AppendInstalledIngresses(ctx context.Context, manifest *mf.Manifest, instance base.KComponent) error { | ||
| version := instance.GetStatus().GetVersion() | ||
| if version == "" { | ||
| version = common.TargetVersion(instance) | ||
| } | ||
|
|
||
| m, err := getIngress(version) | ||
| ingressPath := getIngressPath(version, convertToKS(instance)) | ||
| m, err := getIngress(ingressPath) | ||
| if err == nil { | ||
| *manifest = manifest.Append(m) | ||
| } | ||
|
|
||
| // It is possible that the ingress is not available with the specified version. | ||
| // If the user specified a version with a minor version, which is not supported by the current operator, as long as | ||
| // spec.manifests contains all the manifest links, the operator can still work. This function can always return nil, | ||
| // If the user specified a version with a minor version, which is not supported by the current operator, the operator | ||
| // can still work, as long as spec.manifests contains all the manifest links. This function can always return nil, | ||
| // even if the ingress is not available. | ||
| return nil | ||
| } | ||
|
|
||
| func hasProviderLabel(u *unstructured.Unstructured) bool { | ||
| if _, hasLabel := u.GetLabels()[providerLabel]; hasLabel { | ||
| return true | ||
| func convertToKS(instance base.KComponent) *v1beta1.KnativeServing { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exact same function exists in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. |
||
| ks := &v1beta1.KnativeServing{} | ||
| switch instance := instance.(type) { | ||
| case *v1beta1.KnativeServing: | ||
| ks = instance | ||
| } | ||
| return false | ||
| return 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.
Is there a reason why this is called
eventingService? I was first confused with Eventing as we are in theknative-servingpart of the yaml.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.
IngressService or just ingress?
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.
@ReToCode @skonto I changed the name of the field.