Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 5c5473a

Browse files
Add hypershiftlogforwarder controller hosted cluster clients
1 parent 20f8cfe commit 5c5473a

File tree

7 files changed

+336
-139
lines changed

7 files changed

+336
-139
lines changed

controllers/clusterlogforwardertemplate/clusterlogforwardertemplate_controller.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/go-logr/logr"
2626
loggingv1 "github.com/openshift/cluster-logging-operator/apis/logging/v1"
27-
hyperv1beta1 "github.com/openshift/hypershift/api/v1beta1"
2827
"k8s.io/apimachinery/pkg/api/errors"
2928
"k8s.io/apimachinery/pkg/runtime"
3029
"k8s.io/apimachinery/pkg/types"
@@ -36,6 +35,7 @@ import (
3635
"sigs.k8s.io/controller-runtime/pkg/predicate"
3736

3837
hlov1alpha1 "github.com/openshift/hypershift-logging-operator/api/v1alpha1"
38+
"github.com/openshift/hypershift-logging-operator/pkg/hostedcluster"
3939
)
4040

4141
const (
@@ -71,7 +71,7 @@ func (r *ClusterLogForwarderTemplateReconciler) Reconcile(
7171
return ctrl.Result{}, err
7272
}
7373

74-
hcpList, err := r.GetHostedControlPlanes(ctx)
74+
hcpList, err := hostedcluster.GetHostedControlPlanes(r.Client, ctx, false)
7575
if err != nil {
7676
return ctrl.Result{}, err
7777
}
@@ -162,20 +162,6 @@ func (r *ClusterLogForwarderTemplateReconciler) Reconcile(
162162
return ctrl.Result{}, nil
163163
}
164164

165-
// GetHostedControlPlanes returns a list of all hostedcontrolplane resources in all namespaces.
166-
// Basically does `oc get hostedcontrolplane -A`
167-
func (r *ClusterLogForwarderTemplateReconciler) GetHostedControlPlanes(
168-
ctx context.Context,
169-
) ([]hyperv1beta1.HostedControlPlane, error) {
170-
171-
hcpList := new(hyperv1beta1.HostedControlPlaneList)
172-
if err := r.List(ctx, hcpList, &client.ListOptions{Namespace: ""}); err != nil {
173-
return nil, err
174-
}
175-
176-
return hcpList.Items, nil
177-
}
178-
179165
// BuildInputs builds the input array from the template and adds to the clean log forwarder
180166
func (r *ClusterLogForwarderTemplateReconciler) BuildInputs(clusterLogForwarder *loggingv1.ClusterLogForwarder,
181167
logForwarderTemplate *hlov1alpha1.ClusterLogForwarderTemplate) {

controllers/hypershiftlogforwarder/hypershiftlogforwarder_controller.go

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,61 @@ package hypershiftlogforwarder
1919
import (
2020
"context"
2121

22+
"github.com/go-logr/logr"
23+
hlov1alpha1 "github.com/openshift/hypershift-logging-operator/api/v1alpha1"
2224
"k8s.io/apimachinery/pkg/runtime"
2325
ctrl "sigs.k8s.io/controller-runtime"
2426
"sigs.k8s.io/controller-runtime/pkg/client"
27+
"sigs.k8s.io/controller-runtime/pkg/cluster"
28+
"sigs.k8s.io/controller-runtime/pkg/handler"
2529
"sigs.k8s.io/controller-runtime/pkg/log"
26-
27-
managedv1alpha1 "github.com/openshift/hypershift-logging-operator/api/v1alpha1"
30+
"sigs.k8s.io/controller-runtime/pkg/source"
2831
)
2932

33+
// HostedCluster keeps hosted cluster info
34+
type HostedCluster struct {
35+
Cluster cluster.Cluster
36+
ClusterId string
37+
HCPNamespace string
38+
}
39+
3040
// HyperShiftLogForwarderReconciler reconciles a HyperShiftLogForwarder object
3141
type HyperShiftLogForwarderReconciler struct {
3242
client.Client
33-
Scheme *runtime.Scheme
43+
Scheme *runtime.Scheme
44+
MCClint client.Client
45+
HCPNamespace string
46+
log logr.Logger
47+
}
48+
49+
// NewLogForwarderReconcilerReconciler ...
50+
func NewHyperShiftLogForwarderReconciler(mgr ctrl.Manager, hostedClusters map[string]HostedCluster) (*HyperShiftLogForwarderReconciler, error) {
51+
r := HyperShiftLogForwarderReconciler{
52+
Scheme: mgr.GetScheme(),
53+
}
54+
55+
for _, hostedCluster := range hostedClusters {
56+
r := HyperShiftLogForwarderReconciler{
57+
Client: hostedCluster.Cluster.GetClient(),
58+
Scheme: mgr.GetScheme(),
59+
MCClint: mgr.GetClient(),
60+
HCPNamespace: hostedCluster.HCPNamespace,
61+
}
62+
63+
err := ctrl.NewControllerManagedBy(mgr).
64+
For(&hlov1alpha1.HyperShiftLogForwarder{}).
65+
Watches(
66+
source.NewKindWithCache(&hlov1alpha1.HyperShiftLogForwarder{}, hostedCluster.Cluster.GetCache()),
67+
&handler.EnqueueRequestForObject{},
68+
).
69+
Complete(&r)
70+
if err != nil {
71+
72+
return &r, err
73+
}
74+
}
75+
76+
return &r, nil
3477
}
3578

3679
//+kubebuilder:rbac:groups=logging.managed.openshift.io,resources=hypershiftlogforwarders,verbs=get;list;watch;create;update;patch;delete
@@ -53,10 +96,3 @@ func (r *HyperShiftLogForwarderReconciler) Reconcile(ctx context.Context, req ct
5396

5497
return ctrl.Result{}, nil
5598
}
56-
57-
// SetupWithManager sets up the controller with the Manager.
58-
func (r *HyperShiftLogForwarderReconciler) SetupWithManager(mgr ctrl.Manager) error {
59-
return ctrl.NewControllerManagedBy(mgr).
60-
For(&managedv1alpha1.HyperShiftLogForwarder{}).
61-
Complete(r)
62-
}

go.mod

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.19
44

55
require (
66
github.com/go-logr/logr v1.2.4
7-
github.com/openshift/api v0.0.0-20230825144922-938af62eda38
87
github.com/openshift/cluster-logging-operator v0.0.0-20230824003206-e87beec8402b
98
github.com/openshift/hypershift v0.1.9
109
k8s.io/api v0.28.1
@@ -15,13 +14,6 @@ require (
1514
)
1615

1716
require (
18-
cloud.google.com/go v0.99.0 // indirect
19-
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
20-
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
21-
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
22-
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
23-
github.com/Azure/go-autorest/logger v0.2.1 // indirect
24-
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
2517
github.com/beorn7/perks v1.0.1 // indirect
2618
github.com/blang/semver v3.5.1+incompatible // indirect
2719
github.com/blang/semver/v4 v4.0.0 // indirect
@@ -37,12 +29,12 @@ require (
3729
github.com/gobuffalo/flect v0.2.5 // indirect
3830
github.com/gogo/protobuf v1.3.2 // indirect
3931
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
40-
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
4132
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4233
github.com/golang/protobuf v1.5.3 // indirect
4334
github.com/google/gnostic v0.5.7-v3refs // indirect
4435
github.com/google/go-cmp v0.5.9 // indirect
4536
github.com/google/gofuzz v1.2.0 // indirect
37+
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
4638
github.com/google/uuid v1.3.0 // indirect
4739
github.com/imdario/mergo v0.3.12 // indirect
4840
github.com/josharian/intern v1.0.0 // indirect
@@ -54,6 +46,7 @@ require (
5446
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5547
github.com/onsi/ginkgo/v2 v2.12.0 // indirect
5648
github.com/onsi/gomega v1.27.10 // indirect
49+
github.com/openshift/api v0.0.0-20230825144922-938af62eda38 // indirect
5750
github.com/openshift/elasticsearch-operator v0.0.0-20220613183908-e1648e67c298 // indirect
5851
github.com/pkg/errors v0.9.1 // indirect
5952
github.com/prometheus/client_golang v1.16.0 // indirect

0 commit comments

Comments
 (0)