Skip to content

Commit

Permalink
feat: watch Ingress CR updates
Browse files Browse the repository at this point in the history
- if user set appsDomain, we need to trigger changes to reflect it
	- only on update event
	- only check cluster CR
	- set in cache
- move ingresscontroller to watch than own it

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Oct 25, 2024
1 parent bde4b4e commit 259c0e7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ spec:
Internal development useful field to test customizations.
This is not recommended to be used in production environment.
properties:
logLevel:
description: Override Zap log level. Can be "debug", "info", "error"
or a number (more verbose).
type: string
logmode:
default: production
description: '## DEPRECATED ##: Ignored, use LogLevel instead'
enum:
- devel
- development
Expand Down
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
37 changes: 36 additions & 1 deletion controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
Expand All @@ -57,6 +58,7 @@ import (
"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 @@ func (r *DataScienceClusterReconciler) SetupWithManager(ctx context.Context, mgr
Owns(&imagev1.ImageStream{}).
Owns(&buildv1.BuildConfig{}).
Owns(&apiregistrationv1.APIService{}).
Owns(&networkingv1.Ingress{}).
Owns(&admissionregistrationv1.MutatingWebhookConfiguration{}).
Owns(
&admissionregistrationv1.ValidatingWebhookConfiguration{},
Expand Down Expand Up @@ -531,6 +532,24 @@ func (r *DataScienceClusterReconciler) SetupWithManager(ctx context.Context, mgr
}),
builder.WithPredicates(argoWorkflowCRDPredicates),
).
Watches( // ingresscontroller
&networkingv1.Ingress{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []reconcile.Request {
return r.watchDefaultIngressSecret(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
).
Watches( // ingress
&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "config.openshift.io/v1",
"kind": "Ingress",
},
},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []reconcile.Request {
return r.watchIngressResources(ctx, a)
}),

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

View check run for this annotation

Codecov / codecov/patch

controllers/datasciencecluster/datasciencecluster_controller.go#L548-L550

Added lines #L548 - L550 were not covered by tests
builder.WithPredicates(updatePredicates),
).
Watches(
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []reconcile.Request {
Expand Down Expand Up @@ -635,6 +654,22 @@ func (r *DataScienceClusterReconciler) watchDefaultIngressSecret(ctx context.Con
return nil
}

func (r *DataScienceClusterReconciler) watchIngressResources(ctx context.Context, a client.Object) []reconcile.Request {
requestName, err := r.getRequestName(ctx)
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 664 in controllers/datasciencecluster/datasciencecluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/datasciencecluster/datasciencecluster_controller.go#L657-L664

Added lines #L657 - L664 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

controllers/datasciencecluster/datasciencecluster_controller.go#L668-L670

Added lines #L668 - L670 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
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -67,6 +68,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/secretgenerator"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/webhook"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/logger"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
)
Expand Down Expand Up @@ -179,9 +181,14 @@ func main() { //nolint:funlen,maintidx

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

uingress := &unstructured.Unstructured{}
uingress.SetGroupVersionKind(gvk.OpenshiftIngress)

cacheOptions := cache.Options{
Scheme: scheme,
ByObject: map[client.Object]cache.ByObject{
uingress: {},
// 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

0 comments on commit 259c0e7

Please sign in to comment.