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: Update controller runtime #1064

Merged
merged 39 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6749bca
Initial update controller runtime
AndrienkoAleksandr Sep 7, 2021
8aa7233
Fix zap logger usage in the unit tests.
AndrienkoAleksandr Sep 7, 2021
038b537
Adapt custom signal handler to new controller runtime.
AndrienkoAleksandr Sep 7, 2021
7000b51
Enable image puller.
AndrienkoAleksandr Sep 13, 2021
c2e3c60
Uncomment more tests.
AndrienkoAleksandr Sep 13, 2021
9de294e
Update dependencies.
AndrienkoAleksandr Sep 14, 2021
c69ac35
Freeze new deps.
AndrienkoAleksandr Sep 14, 2021
b704c66
Update deps.
AndrienkoAleksandr Sep 16, 2021
13e7179
Update depths.
AndrienkoAleksandr Sep 16, 2021
bc8acac
Merge branch 'main' of github.com:eclipse-che/che-operator into updat…
AndrienkoAleksandr Sep 16, 2021
b3b827b
Fix failing after resove merge conflict.
AndrienkoAleksandr Sep 16, 2021
0c13f28
Fix format. Fix import. Fix some commented code.
AndrienkoAleksandr Sep 16, 2021
6bf2a04
Fix up.
AndrienkoAleksandr Sep 16, 2021
e54b861
Fix up.
AndrienkoAleksandr Sep 16, 2021
d223a36
Update bundle. Fix image puller api registration.
AndrienkoAleksandr Sep 16, 2021
3c6fbc8
Fix import.
AndrienkoAleksandr Sep 18, 2021
4b626ea
Merge branch 'main' of github.com:eclipse-che/che-operator into updat…
AndrienkoAleksandr Sep 18, 2021
e97e030
Update bundle
AndrienkoAleksandr Sep 18, 2021
7be6a9d
Fix tests after resolve merge conflict. Again...
AndrienkoAleksandr Sep 18, 2021
4e66498
Revert previous delete logic
AndrienkoAleksandr Sep 20, 2021
26676c6
Merge branch 'main' of github.com:eclipse-che/che-operator into updat…
AndrienkoAleksandr Sep 20, 2021
5f88eb4
Fix Minishift ci tests.
AndrienkoAleksandr Sep 20, 2021
a6c6e09
Improve leader election check.
AndrienkoAleksandr Sep 21, 2021
1e2f63b
Fix format.
AndrienkoAleksandr Sep 21, 2021
b7ee691
Test commit...
AndrienkoAleksandr Sep 21, 2021
538bf3d
Fix update test.
AndrienkoAleksandr Sep 21, 2021
38fff16
Fix up.
AndrienkoAleksandr Sep 21, 2021
25ffbac
Update CRD...
AndrienkoAleksandr Sep 21, 2021
ce062dc
Update bundle.
AndrienkoAleksandr Sep 21, 2021
c546b9f
Code clean up.
AndrienkoAleksandr Sep 21, 2021
78a4e95
Merge branch 'main' of github.com:eclipse-che/che-operator into updat…
AndrienkoAleksandr Sep 21, 2021
bcfda6c
Fix compilation
AndrienkoAleksandr Sep 21, 2021
821c0d6
Fix tests compilation.
AndrienkoAleksandr Sep 21, 2021
ead556a
Update bundle.
AndrienkoAleksandr Sep 21, 2021
d6e2e86
Merge branch 'main' of github.com:eclipse-che/che-operator into updat…
AndrienkoAleksandr Sep 30, 2021
4b3be90
Update bundle.
AndrienkoAleksandr Sep 30, 2021
5c420f4
Add information about approved CQ for new controller runtime.
AndrienkoAleksandr Sep 30, 2021
3ef881c
Point image puller commit to main branch.
AndrienkoAleksandr Sep 30, 2021
0ab672d
Fix up.
AndrienkoAleksandr Sep 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"group": "build"
},
{
"label": "Update che-operator dependencies",
"label": "Update golang dependencies",
"command": "go mod tidy; go mod vendor",
"type": "shell",
"args": [],
Expand Down
613 changes: 82 additions & 531 deletions Dependencies.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"testing"

"github.com/che-incubator/kubernetes-image-puller-operator/pkg/apis/che/v1alpha1"
"github.com/che-incubator/kubernetes-image-puller-operator/api/v1alpha1"
v1 "github.com/eclipse-che/che-operator/api/v1"
"github.com/eclipse-che/che-operator/api/v2alpha1"
"github.com/eclipse-che/che-operator/pkg/util"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package v1
// IMPORTANT These 2 last steps are important to ensure backward compatibility with already existing `CheCluster` CRs that were created when no schema was provided.

import (
chev1alpha1 "github.com/che-incubator/kubernetes-image-puller-operator/pkg/apis/che/v1alpha1"
chev1alpha1 "github.com/che-incubator/kubernetes-image-puller-operator/api/v1alpha1"
v2alpha1 "github.com/eclipse-che/che-operator/api/v2alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-openshift.v7.37.0-348.next
name: eclipse-che-preview-openshift.v7.37.0-349.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -344,6 +344,7 @@ spec:
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand All @@ -353,6 +354,7 @@ spec:
- list
- create
- update
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -872,7 +874,7 @@ spec:
- name: RELATED_IMAGE_devfile_registry
value: quay.io/eclipse/che-devfile-registry:next
- name: RELATED_IMAGE_pvc_jobs
value: registry.access.redhat.com/ubi8-minimal:8.4-208
value: registry.access.redhat.com/ubi8-minimal:8.4-210
- name: RELATED_IMAGE_postgres
value: quay.io/eclipse/che--centos--postgresql-96-centos7:9.6-b681d78125361519180a6ac05242c296f8906c11eab7e207b5ca9a89b6344392
- name: RELATED_IMAGE_keycloak
Expand Down Expand Up @@ -1198,4 +1200,4 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.37.0-348.next
version: 7.37.0-349.next
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ spec:
description: A KubernetesImagePullerSpec to configure the image
puller in the CheCluster
properties:
affinity:
type: string
cachingCPULimit:
type: string
cachingCPURequest:
Expand All @@ -409,6 +411,8 @@ spec:
type: string
imagePullSecrets:
type: string
imagePullerImage:
type: string
images:
type: string
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-kubernetes.v7.37.0-309.next
name: eclipse-che-preview-kubernetes.v7.37.0-310.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1175,4 +1175,4 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.37.0-309.next
version: 7.37.0-310.next
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ spec:
spec:
description: A KubernetesImagePullerSpec to configure the image puller in the CheCluster
properties:
affinity:
type: string
cachingCPULimit:
type: string
cachingCPURequest:
Expand All @@ -252,6 +254,8 @@ spec:
type: string
imagePullSecrets:
type: string
imagePullerImage:
type: string
images:
type: string
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-openshift.v7.37.0-316.next
name: eclipse-che-preview-openshift.v7.37.0-317.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1200,4 +1200,4 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.37.0-316.next
version: 7.37.0-317.next
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ spec:
description: A KubernetesImagePullerSpec to configure the image
puller in the CheCluster
properties:
affinity:
type: string
cachingCPULimit:
type: string
cachingCPURequest:
Expand All @@ -409,6 +411,8 @@ spec:
type: string
imagePullSecrets:
type: string
imagePullerImage:
type: string
images:
type: string
nodeSelector:
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/org_v1_che_crd-v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ spec:
description: A KubernetesImagePullerSpec to configure the image
puller in the CheCluster
properties:
affinity:
type: string
cachingCPULimit:
type: string
cachingCPURequest:
Expand All @@ -396,6 +398,8 @@ spec:
type: string
imagePullSecrets:
type: string
imagePullerImage:
type: string
images:
type: string
nodeSelector:
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/org_v1_che_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ spec:
description: A KubernetesImagePullerSpec to configure the image
puller in the CheCluster
properties:
affinity:
type: string
cachingCPULimit:
type: string
cachingCPURequest:
Expand All @@ -409,6 +411,8 @@ spec:
type: string
imagePullSecrets:
type: string
imagePullerImage:
type: string
images:
type: string
nodeSelector:
Expand Down
4 changes: 2 additions & 2 deletions controllers/che/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
fakeclientset "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)

func TestGetBackupServerConfigurationNameForBackupBeforeUpdate(t *testing.T) {
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestGetBackupServerConfigurationNameForBackupBeforeUpdate(t *testing.T) {

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
logf.SetLogger(zap.LoggerTo(os.Stdout, true))
logf.SetLogger(zap.New(zap.WriteTo(os.Stdout), zap.UseDevMode(true)))
chev1.SchemeBuilder.AddToScheme(scheme.Scheme)
testCase.initObjects = append(testCase.initObjects, testCase.backupServerConfigs, testCase.cheCluster)

Expand Down
32 changes: 14 additions & 18 deletions controllers/che/checluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,11 @@ type CheClusterReconciler struct {
}

// NewReconciler returns a new CheClusterReconciler
func NewReconciler(mgr ctrl.Manager, namespace string) (*CheClusterReconciler, error) {
func NewReconciler(mgr ctrl.Manager, namespace string, discoveryClient *discovery.DiscoveryClient) (*CheClusterReconciler, error) {
noncachedClient, err := client.New(mgr.GetConfig(), client.Options{Scheme: mgr.GetScheme()})
if err != nil {
return nil, err
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig())
if err != nil {
return nil, err
}
return &CheClusterReconciler{
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("CheCluster"),
Expand Down Expand Up @@ -140,15 +136,15 @@ func (r *CheClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
},
}

var toTrustedBundleConfigMapRequestMapper handler.ToRequestsFunc = func(obj handler.MapObject) []ctrl.Request {
var toTrustedBundleConfigMapRequestMapper handler.MapFunc = func(obj client.Object) []ctrl.Request {
isTrusted, reconcileRequest := isTrustedBundleConfigMap(mgr, obj)
if isTrusted {
return []ctrl.Request{reconcileRequest}
}
return []ctrl.Request{}
}

var toEclipseCheRelatedObjRequestMapper handler.ToRequestsFunc = func(obj handler.MapObject) []ctrl.Request {
var toEclipseCheRelatedObjRequestMapper handler.MapFunc = func(obj client.Object) []ctrl.Request {
isEclipseCheRelatedObj, reconcileRequest := isEclipseCheRelatedObj(mgr, obj)
if isEclipseCheRelatedObj {
return []ctrl.Request{reconcileRequest}
Expand Down Expand Up @@ -193,15 +189,15 @@ func (r *CheClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
OwnerType: &orgv1.CheCluster{},
}).
Watches(&source.Kind{Type: &corev1.ConfigMap{}},
&handler.EnqueueRequestsFromMapFunc{ToRequests: toTrustedBundleConfigMapRequestMapper},
handler.EnqueueRequestsFromMapFunc(toTrustedBundleConfigMapRequestMapper),
builder.WithPredicates(onAllExceptGenericEventsPredicate),
).
Watches(&source.Kind{Type: &corev1.Secret{}},
&handler.EnqueueRequestsFromMapFunc{ToRequests: toEclipseCheRelatedObjRequestMapper},
handler.EnqueueRequestsFromMapFunc(toEclipseCheRelatedObjRequestMapper),
builder.WithPredicates(onAllExceptGenericEventsPredicate),
).
Watches(&source.Kind{Type: &corev1.ConfigMap{}},
&handler.EnqueueRequestsFromMapFunc{ToRequests: toEclipseCheRelatedObjRequestMapper},
handler.EnqueueRequestsFromMapFunc(toEclipseCheRelatedObjRequestMapper),
builder.WithPredicates(onAllExceptGenericEventsPredicate),
)

Expand Down Expand Up @@ -230,8 +226,8 @@ func (r *CheClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
// move the current state of the cluster closer to the desired state.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.6.3/pkg/reconcile
func (r *CheClusterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.9.5/pkg/reconcile
func (r *CheClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("checluster", req.NamespacedName)

clusterAPI := deploy.ClusterAPI{
Expand Down Expand Up @@ -659,7 +655,7 @@ func (r *CheClusterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
}

// isTrustedBundleConfigMap detects whether given config map is the config map with additional CA certificates to be trusted by Che
func isTrustedBundleConfigMap(mgr ctrl.Manager, obj handler.MapObject) (bool, ctrl.Request) {
func isTrustedBundleConfigMap(mgr ctrl.Manager, obj client.Object) (bool, ctrl.Request) {
checlusters := &orgv1.CheClusterList{}
if err := mgr.GetClient().List(context.TODO(), checlusters, &client.ListOptions{}); err != nil {
return false, ctrl.Request{}
Expand All @@ -670,18 +666,18 @@ func isTrustedBundleConfigMap(mgr ctrl.Manager, obj handler.MapObject) (bool, ct
}

// Check if config map is the config map from CR
if checlusters.Items[0].Spec.Server.ServerTrustStoreConfigMapName != obj.Meta.GetName() {
if checlusters.Items[0].Spec.Server.ServerTrustStoreConfigMapName != obj.GetName() {
// No, it is not form CR
// Check for labels

// Check for part of Che label
if value, exists := obj.Meta.GetLabels()[deploy.KubernetesPartOfLabelKey]; !exists || value != deploy.CheEclipseOrg {
if value, exists := obj.GetLabels()[deploy.KubernetesPartOfLabelKey]; !exists || value != deploy.CheEclipseOrg {
// Labels do not match
return false, ctrl.Request{}
}

// Check for CA bundle label
if value, exists := obj.Meta.GetLabels()[deploy.CheCACertsConfigMapLabelKey]; !exists || value != deploy.CheCACertsConfigMapLabelValue {
if value, exists := obj.GetLabels()[deploy.CheCACertsConfigMapLabelKey]; !exists || value != deploy.CheCACertsConfigMapLabelValue {
// Labels do not match
return false, ctrl.Request{}
}
Expand Down Expand Up @@ -775,7 +771,7 @@ func (r *CheClusterReconciler) autoEnableOAuth(deployContext *deploy.DeployConte

// isEclipseCheRelatedObj indicates if there is a object with
// the label 'app.kubernetes.io/part-of=che.eclipse.org' in a che namespace
func isEclipseCheRelatedObj(mgr ctrl.Manager, obj handler.MapObject) (bool, ctrl.Request) {
func isEclipseCheRelatedObj(mgr ctrl.Manager, obj client.Object) (bool, ctrl.Request) {
checlusters := &orgv1.CheClusterList{}
if err := mgr.GetClient().List(context.TODO(), checlusters, &client.ListOptions{}); err != nil {
return false, ctrl.Request{}
Expand All @@ -785,7 +781,7 @@ func isEclipseCheRelatedObj(mgr ctrl.Manager, obj handler.MapObject) (bool, ctrl
return false, ctrl.Request{}
}

if value, exists := obj.Meta.GetLabels()[deploy.KubernetesPartOfLabelKey]; !exists || value != deploy.CheEclipseOrg {
if value, exists := obj.GetLabels()[deploy.KubernetesPartOfLabelKey]; !exists || value != deploy.CheEclipseOrg {
// Labels do not match
return false, ctrl.Request{}
}
Expand Down
Loading