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

feat: watch Ingress CR updates #1319

Open
wants to merge 3 commits into
base: incubation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,11 @@ spec:
resources:
- authentications
- clusterversions
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
- ingresses
verbs:
- get
- apiGroups:
- console.openshift.io
resources:
Expand Down
7 changes: 1 addition & 6 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,11 @@ rules:
resources:
- authentications
- clusterversions
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
- ingresses
verbs:
- get
- apiGroups:
- console.openshift.io
resources:
Expand Down
29 changes: 27 additions & 2 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"github.com/go-logr/logr"
"github.com/hashicorp/go-multierror"
buildv1 "github.com/openshift/api/build/v1"
configv1 "github.com/openshift/api/config/v1"
imagev1 "github.com/openshift/api/image/v1"
operatorv1 "github.com/openshift/api/operator/v1"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
Expand Down Expand Up @@ -57,6 +58,7 @@
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
annotations "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
Expand Down Expand Up @@ -501,7 +503,6 @@
Owns(&imagev1.ImageStream{}).
Owns(&buildv1.BuildConfig{}).
Owns(&apiregistrationv1.APIService{}).
Owns(&operatorv1.IngressController{}).
Owns(&admissionregistrationv1.MutatingWebhookConfiguration{}).
Owns(
&admissionregistrationv1.ValidatingWebhookConfiguration{},
Expand Down Expand Up @@ -531,12 +532,20 @@
}),
builder.WithPredicates(argoWorkflowCRDPredicates),
).
Watches( // ingress
&configv1.Ingress{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []reconcile.Request {
return r.watchIngressResources(ctx, a)
}),

Check warning on line 539 in controllers/datasciencecluster/datasciencecluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/datasciencecluster/datasciencecluster_controller.go#L537-L539

Added lines #L537 - L539 were not covered by tests
builder.WithPredicates(generalUpdatePredicates),
).
Watches(
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []reconcile.Request {
return r.watchDefaultIngressSecret(ctx, a)
}),
builder.WithPredicates(defaultIngressCertSecretPredicates)).
builder.WithPredicates(defaultIngressCertSecretPredicates),
).
// this predicates prevents meaningless reconciliations from being triggered
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{})).
Complete(r)
Expand Down Expand Up @@ -635,6 +644,22 @@
return nil
}

func (r *DataScienceClusterReconciler) watchIngressResources(ctx context.Context, a client.Object) []reconcile.Request {
requestName, err := r.getRequestName(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated, but getRequestName seems incorrect as it would return a result even if there's no actual instances of a DSC

Copy link
Member Author

Choose a reason for hiding this comment

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

let me make another PR to follow this 0 instance case.
the original code was added 10 months ago.....

Copy link
Member Author

Choose a reason for hiding this comment

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

follow up in #1323

if err != nil || a.GetName() != "cluster" || a.GetObjectKind().GroupVersionKind() != gvk.OpenshiftIngress {
return nil
}
return []reconcile.Request{{
NamespacedName: types.NamespacedName{Name: requestName},
}}

Check warning on line 654 in controllers/datasciencecluster/datasciencecluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/datasciencecluster/datasciencecluster_controller.go#L647-L654

Added lines #L647 - L654 were not covered by tests
}

var generalUpdatePredicates = predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return true
},

Check warning on line 660 in controllers/datasciencecluster/datasciencecluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/datasciencecluster/datasciencecluster_controller.go#L658-L660

Added lines #L658 - L660 were not covered by tests
}

// defaultIngressCertSecretPredicates filters delete and create events to trigger reconcile when default ingress cert secret is expired
// or created.
var defaultIngressCertSecretPredicates = predicate.Funcs{
Expand Down
2 changes: 1 addition & 1 deletion controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package datasciencecluster
/* Serverless prerequisite */
// +kubebuilder:rbac:groups="networking.istio.io",resources=gateways,verbs=*
// +kubebuilder:rbac:groups="operator.knative.dev",resources=knativeservings,verbs=*
// +kubebuilder:rbac:groups="config.openshift.io",resources=ingresses,verbs=get
// +kubebuilder:rbac:groups="config.openshift.io",resources=ingresses,verbs=get;watch;list

/* Service Mesh Integration */
// +kubebuilder:rbac:groups="maistra.io",resources=servicemeshcontrolplanes,verbs=create;get;list;patch;update;use;watch
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ func main() { //nolint:funlen,maintidx

secretCache := createSecretCacheConfig(platform)
deploymentCache := createDeploymentCacheConfig(platform)

cacheOptions := cache.Options{
Scheme: scheme,
ByObject: map[client.Object]cache.ByObject{
// for Ingress from config.openshift.io/v1
&configv1.Ingress{}: {
Field: fields.Set{"metadata.name": "cluster"}.AsSelector(),
},
// all CRD: mainly for pipeline v1 teckon and v2 argo and dashboard's own CRD
&apiextensionsv1.CustomResourceDefinition{}: {},
// Cannot find a label on various screts, so we need to watch all secrets
Expand Down