Skip to content

Commit

Permalink
Merge pull request #176 from boranx/MultiNamespacedCacheBuilder
Browse files Browse the repository at this point in the history
feat(cmd): apply MultiNamespacedCacheBuilder, bump-up controller-runtime to 0.8.3
  • Loading branch information
openshift-merge-robot committed May 25, 2021
2 parents 3ef81f3 + ce32228 commit 6e0ff56
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 119 deletions.
2 changes: 1 addition & 1 deletion deploy/50_cloud-ingress-operator.Deployment.yaml
Expand Up @@ -36,7 +36,7 @@ spec:
env:
# "" so that the cache can read objects outside its namespace
- name: WATCH_NAMESPACE
value: ""
value: "openshift-sre-sshd,openshift-cloud-ingress-operator,openshift-ingress,openshift-ingress-operator,openshift-kube-apiserver"
- name: POD_NAME
valueFrom:
fieldRef:
Expand Down
19 changes: 11 additions & 8 deletions go.mod
@@ -1,6 +1,6 @@
module github.com/openshift/cloud-ingress-operator

go 1.13
go 1.15

require (
github.com/aws/aws-sdk-go v1.38.38
Expand All @@ -12,23 +12,26 @@ require (
github.com/openshift/machine-api-operator v0.2.1-0.20200226185612-9b0170a1ba07
github.com/openshift/operator-custom-metrics v0.4.2
github.com/operator-framework/operator-sdk v0.18.2
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/client_golang v1.7.1
github.com/spf13/pflag v1.0.5
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
google.golang.org/api v0.35.0
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.18.6
k8s.io/apimachinery v0.18.6
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
sigs.k8s.io/cluster-api-provider-aws v0.0.0
sigs.k8s.io/controller-runtime v0.6.5
sigs.k8s.io/controller-runtime v0.8.3
)

replace (
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.3.2+incompatible // Required by OLM
k8s.io/client-go => k8s.io/client-go v0.18.6 // Required by prometheus-operator
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.0
k8s.io/api => k8s.io/api v0.19.2
k8s.io/apimachinery => k8s.io/apimachinery v0.19.2
k8s.io/client-go => k8s.io/client-go v0.19.2 // Required by prometheus-operator
)

replace sigs.k8s.io/cluster-api-provider-aws => github.com/openshift/cluster-api-provider-aws v0.2.1-0.20200204144622-0df2d100309c // Pin OpenShift fork
181 changes: 103 additions & 78 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/cloudclient/aws/private.go
Expand Up @@ -129,7 +129,7 @@ func updateAWSLBList(kclient client.Client, oldLBList []awsproviderapi.LoadBalan
return err
}
machineToPatch.Spec.ProviderSpec = *newProviderSpecEncoded
machineObj := machineToPatch.DeepCopyObject()
machineObj := machineToPatch.DeepCopy()
if err := kclient.Patch(context.Background(), machineObj, baseToPatch); err != nil {
log.Error(err, "Failed to update LBs in machine's providerSpec", "machine", machineToPatch.Name)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudclient/gcp/private.go
Expand Up @@ -407,7 +407,7 @@ func updateGCPLBList(kclient client.Client, oldLBList []string, newLBList []stri
return err
}
machineToPatch.Spec.ProviderSpec.Value = newProviderSpecEncoded
machineObj := machineToPatch.DeepCopyObject()
machineObj := machineToPatch.DeepCopy()
if err := kclient.Patch(context.Background(), machineObj, baseToPatch); err != nil {
log.Error(err, "Failed to update LBs in machine's providerSpec", "machine", machineToPatch.Name)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/apischeme/apischeme_controller.go
Expand Up @@ -97,7 +97,7 @@ type LoadBalancer struct {
// 1. Create Service
// 2. Add DNS CNAME from rh-api to the ELB created by AWS provider
// 3. Ready for work (Ready)
func (r *ReconcileAPIScheme) Reconcile(request reconcile.Request) (reconcile.Result, error) {
func (r *ReconcileAPIScheme) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling APIScheme")

Expand Down
Expand Up @@ -85,7 +85,7 @@ type ReconcilePublishingStrategy struct {
// Note:
// The Controller will requeue the Request to be processed again if the returned error is non-nil or
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcilePublishingStrategy) Reconcile(request reconcile.Request) (reconcile.Result, error) {
func (r *ReconcilePublishingStrategy) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling PublishingStrategy")

Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/routerservice/router_service_controller.go
Expand Up @@ -48,10 +48,12 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Only filter on services in the openshift-ingress namespace and create/update events
p := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
return e.Meta.GetNamespace() == RouterServiceNamespace
return e.Object.GetNamespace() == RouterServiceNamespace

},
UpdateFunc: func(e event.UpdateEvent) bool {
return e.MetaNew.GetNamespace() == RouterServiceNamespace
return e.ObjectNew.GetNamespace() == RouterServiceNamespace

},
}

Expand Down Expand Up @@ -80,7 +82,7 @@ type ReconcileRouterService struct {
// Note:
// The Controller will requeue the Request to be processed again if the returned error is non-nil or
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcileRouterService) Reconcile(request reconcile.Request) (reconcile.Result, error) {
func (r *ReconcileRouterService) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)

// Fetch the Service
Expand Down
16 changes: 7 additions & 9 deletions pkg/controller/routerservice/router_service_controller_test.go
Expand Up @@ -6,7 +6,6 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -37,16 +36,15 @@ func TestRouterServiceController(t *testing.T) {
},
}

// Objects to track in the fake client.
objs := []runtime.Object{
routerDefaultSvc,
}

// Register operator types with the runtime scheme.
s := scheme.Scheme

// Create a fake client to mock API calls.
cl := fake.NewFakeClient(objs...)
cl := fake.
NewClientBuilder().
WithScheme(s).
WithObjects(routerDefaultSvc).
Build()

s.AddKnownTypes(corev1.SchemeGroupVersion, routerDefaultSvc)

Expand All @@ -63,7 +61,7 @@ func TestRouterServiceController(t *testing.T) {
},
}
log.Info("Calling Reconcile()")
res, err := r.Reconcile(req)
res, err := r.Reconcile(context.TODO(), req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}
Expand All @@ -75,7 +73,7 @@ func TestRouterServiceController(t *testing.T) {

// Reconcile again so Reconcile() checks routes and updates the Service
// resources' Status.
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/sshd/sshd_controller.go
Expand Up @@ -120,7 +120,7 @@ const (
// Note:
// The Controller will requeue the Request to be processed again if the returned error is non-nil or
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *ReconcileSSHD) Reconcile(request reconcile.Request) (reconcile.Result, error) {
func (r *ReconcileSSHD) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling SSHD")

Expand Down Expand Up @@ -260,10 +260,7 @@ func (r *ReconcileSSHD) Reconcile(request reconcile.Request) (reconcile.Result,
// Install Deployment
foundDeployment := &appsv1.Deployment{}
deployment := newSSHDDeployment(instance, configMapList, hostKeysSecret)
deploymentName, err := client.ObjectKeyFromObject(deployment)
if err != nil {
return reconcile.Result{}, err
}
deploymentName := client.ObjectKeyFromObject(deployment)
if err = r.client.Get(context.TODO(), deploymentName, foundDeployment); err != nil {
if errors.IsNotFound(err) {
// Create a new Deployment.
Expand Down Expand Up @@ -298,10 +295,7 @@ func (r *ReconcileSSHD) Reconcile(request reconcile.Request) (reconcile.Result,
// Install Service
foundService := &corev1.Service{}
service := newSSHDService(instance)
serviceName, err := client.ObjectKeyFromObject(service)
if err != nil {
return reconcile.Result{}, err
}
serviceName := client.ObjectKeyFromObject(service)
if err = r.client.Get(context.TODO(), serviceName, foundService); err != nil {
if errors.IsNotFound(err) {
// Create a new Service.
Expand Down
6 changes: 2 additions & 4 deletions pkg/controller/sshd/sshd_controller_test.go
Expand Up @@ -245,7 +245,7 @@ func TestReconcile(t *testing.T) {
cloudClient: cloud,
}

result, err := r.Reconcile(reconcile.Request{
result, err := r.Reconcile(context.TODO(), reconcile.Request{
NamespacedName: types.NamespacedName{
Name: placeholderName,
Namespace: placeholderNamespace,
Expand Down Expand Up @@ -334,9 +334,7 @@ func setUpTestClient(t *testing.T) (testClient client.Client, s *runtime.Scheme)
},
}

objects := []runtime.Object{cr, svc, secret}

testClient = fake.NewFakeClientWithScheme(s, objects...)
testClient = fake.NewClientBuilder().WithScheme(s).WithObjects(secret, svc, cr).Build()
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/testutils/testutils.go
Expand Up @@ -106,7 +106,7 @@ func NewTestMock(t *testing.T, localObjs []runtime.Object) *Mocks {
t.Fatalf("Couldn't add cloudingressv1alpha1 scheme: (%v)", err)
}
ret := &Mocks{
FakeKubeClient: fake.NewFakeClientWithScheme(s, localObjs...),
FakeKubeClient: fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(localObjs...).Build(),
MockCtrl: mockctrl,
MockAws: awsclient.NewMockClient(mockctrl),
Scheme: s,
Expand Down
20 changes: 18 additions & 2 deletions pkg/utils/infrastructure.go
Expand Up @@ -8,21 +8,37 @@ import (
"net/url"

configv1 "github.com/openshift/api/config/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// GetInfrastructureObject returns the canonical Infrastructure object
func GetInfrastructureObject(kclient client.Client) (*configv1.Infrastructure, error) {
infra := &configv1.Infrastructure{}
u := &unstructured.Unstructured{}
u.SetGroupVersionKind(schema.GroupVersionKind{
Group: "",
Version: "config.openshift.io/v1",
Kind: "infrastructure",
})
ns := types.NamespacedName{
Namespace: "",
Name: "cluster",
}
err := kclient.Get(context.TODO(), ns, infra)
err := kclient.Get(context.TODO(), ns, u)
if err != nil {
return nil, err
}

uContent := u.UnstructuredContent()
var infra *configv1.Infrastructure
err = runtime.DefaultUnstructuredConverter.FromUnstructured(uContent, &infra)
if err != nil {
return nil, err
}

return infra, nil
}

Expand Down

0 comments on commit 6e0ff56

Please sign in to comment.