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

Update controller runtime to v0.9.5 and k8s dependencies to v0.21.3 #540

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export ROUTING_SUFFIX ?= 192.168.99.100.nip.io
export PULL_POLICY ?= Always
export DEFAULT_ROUTING ?= basic
export KUBECONFIG ?= ${HOME}/.kube/config
export DEVWORKSPACE_API_VERSION ?= 03e023e7078b64884216d8e6dce8f0cf8b7e74d2
export DEVWORKSPACE_API_VERSION ?= ad569a8c7a4988ca08a6b2f139f55de0e55bef96

# Enable using Podman instead of Docker
export DOCKER ?= docker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/google/go-cmp/cmp"
routeV1 "github.com/openshift/api/route/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -58,14 +58,12 @@ type DevWorkspaceRoutingReconciler struct {
// +kubebuilder:rbac:groups=controller.devfile.io,resources=devworkspaceroutings,verbs=*
// +kubebuilder:rbac:groups=controller.devfile.io,resources=devworkspaceroutings/status,verbs=get;update;patch
// +kubebuilder:rbac:groups="",resources=services,verbs=*
// +kubebuilder:rbac:groups=extensions,resources=ingresses,verbs=*
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=*
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=*
// +kubebuidler:rbac:groups=route.openshift.io,resources=routes/status,verbs=get,list,watch
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes/custom-host,verbs=create

func (r *DevWorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
ctx := context.Background()

func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)

// Fetch the DevWorkspaceRouting instance
Expand Down Expand Up @@ -311,7 +309,7 @@ func (r *DevWorkspaceRoutingReconciler) SetupWithManager(mgr ctrl.Manager) error
WithOptions(controller.Options{MaxConcurrentReconciles: maxConcurrentReconciles}).
For(&controllerv1alpha1.DevWorkspaceRouting{}).
Owns(&corev1.Service{}).
Owns(&v1beta1.Ingress{})
Owns(&networkingv1.Ingress{})
if infrastructure.IsOpenShift() {
bld.Owns(&routeV1.Route{})
}
Expand Down
31 changes: 16 additions & 15 deletions controllers/controller/devworkspacerouting/solvers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

routeV1 "github.com/openshift/api/route/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
Expand Down Expand Up @@ -165,8 +165,8 @@ func getRoutesForSpec(routingSuffix string, endpoints map[string]controllerv1alp
return routes
}

func getIngressesForSpec(routingSuffix string, endpoints map[string]controllerv1alpha1.EndpointList, meta DevWorkspaceMetadata) []v1beta1.Ingress {
var ingresses []v1beta1.Ingress
func getIngressesForSpec(routingSuffix string, endpoints map[string]controllerv1alpha1.EndpointList, meta DevWorkspaceMetadata) []networkingv1.Ingress {
var ingresses []networkingv1.Ingress
for _, machineEndpoints := range endpoints {
for _, endpoint := range machineEndpoints {
if endpoint.Exposure != dw.PublicEndpointExposure {
Expand Down Expand Up @@ -208,12 +208,11 @@ func getRouteForEndpoint(routingSuffix string, endpoint dw.Endpoint, meta DevWor
}
}

func getIngressForEndpoint(routingSuffix string, endpoint dw.Endpoint, meta DevWorkspaceMetadata) v1beta1.Ingress {
targetEndpoint := intstr.FromInt(endpoint.TargetPort)
func getIngressForEndpoint(routingSuffix string, endpoint dw.Endpoint, meta DevWorkspaceMetadata) networkingv1.Ingress {
endpointName := common.EndpointName(endpoint.Name)
hostname := common.EndpointHostname(routingSuffix, meta.DevWorkspaceId, endpointName, endpoint.TargetPort)
ingressPathType := v1beta1.PathTypeImplementationSpecific
return v1beta1.Ingress{
ingressPathType := networkingv1.PathTypeImplementationSpecific
return networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: common.RouteName(meta.DevWorkspaceId, endpointName),
Namespace: meta.Namespace,
Expand All @@ -222,17 +221,19 @@ func getIngressForEndpoint(routingSuffix string, endpoint dw.Endpoint, meta DevW
},
Annotations: nginxIngressAnnotations(endpoint.Name),
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: hostname,
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Backend: v1beta1.IngressBackend{
ServiceName: common.ServiceName(meta.DevWorkspaceId),
ServicePort: targetEndpoint,
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: common.ServiceName(meta.DevWorkspaceId),
Port: networkingv1.ServiceBackendPort{Number: int32(endpoint.TargetPort)},
},
},
PathType: &ingressPathType,
Path: "/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"fmt"

routeV1 "github.com/openshift/api/route/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -26,8 +26,8 @@ import (
)

type RoutingObjects struct {
Services []v1.Service
Ingresses []v1beta1.Ingress
Services []corev1.Service
Ingresses []networkingv1.Ingress
Routes []routeV1.Route
PodAdditions *controllerv1alpha1.PodAdditions
}
Expand Down
18 changes: 9 additions & 9 deletions controllers/controller/devworkspacerouting/sync_ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -29,11 +29,11 @@ import (
)

var ingressDiffOpts = cmp.Options{
cmpopts.IgnoreFields(v1beta1.Ingress{}, "TypeMeta", "ObjectMeta", "Status"),
cmpopts.IgnoreFields(v1beta1.HTTPIngressPath{}, "PathType"),
cmpopts.IgnoreFields(networkingv1.Ingress{}, "TypeMeta", "ObjectMeta", "Status"),
cmpopts.IgnoreFields(networkingv1.HTTPIngressPath{}, "PathType"),
}

func (r *DevWorkspaceRoutingReconciler) syncIngresses(routing *controllerv1alpha1.DevWorkspaceRouting, specIngresses []v1beta1.Ingress) (ok bool, clusterIngresses []v1beta1.Ingress, err error) {
func (r *DevWorkspaceRoutingReconciler) syncIngresses(routing *controllerv1alpha1.DevWorkspaceRouting, specIngresses []networkingv1.Ingress) (ok bool, clusterIngresses []networkingv1.Ingress, err error) {
ingressesInSync := true

clusterIngresses, err = r.getClusterIngresses(routing)
Expand Down Expand Up @@ -74,8 +74,8 @@ func (r *DevWorkspaceRoutingReconciler) syncIngresses(routing *controllerv1alpha
return ingressesInSync, clusterIngresses, nil
}

func (r *DevWorkspaceRoutingReconciler) getClusterIngresses(routing *controllerv1alpha1.DevWorkspaceRouting) ([]v1beta1.Ingress, error) {
found := &v1beta1.IngressList{}
func (r *DevWorkspaceRoutingReconciler) getClusterIngresses(routing *controllerv1alpha1.DevWorkspaceRouting) ([]networkingv1.Ingress, error) {
found := &networkingv1.IngressList{}
labelSelector, err := labels.Parse(fmt.Sprintf("%s=%s", constants.DevWorkspaceIDLabel, routing.Spec.DevWorkspaceId))
if err != nil {
return nil, err
Expand All @@ -91,8 +91,8 @@ func (r *DevWorkspaceRoutingReconciler) getClusterIngresses(routing *controllerv
return found.Items, nil
}

func getIngressesToDelete(clusterIngresses, specIngresses []v1beta1.Ingress) []v1beta1.Ingress {
var toDelete []v1beta1.Ingress
func getIngressesToDelete(clusterIngresses, specIngresses []networkingv1.Ingress) []networkingv1.Ingress {
var toDelete []networkingv1.Ingress
for _, clusterIngress := range clusterIngresses {
if contains, _ := listContainsIngressByName(clusterIngress, specIngresses); !contains {
toDelete = append(toDelete, clusterIngress)
Expand All @@ -101,7 +101,7 @@ func getIngressesToDelete(clusterIngresses, specIngresses []v1beta1.Ingress) []v
return toDelete
}

func listContainsIngressByName(query v1beta1.Ingress, list []v1beta1.Ingress) (exists bool, idx int) {
func listContainsIngressByName(query networkingv1.Ingress, list []networkingv1.Ingress) (exists bool, idx int) {
for idx, listIngress := range list {
if query.Name == listIngress.Name {
return true, idx
Expand Down
13 changes: 6 additions & 7 deletions controllers/workspace/devworkspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type DevWorkspaceReconciler struct {
// +kubebuilder:rbac:groups=workspace.devfile.io,resources=*,verbs=*
// +kubebuilder:rbac:groups=controller.devfile.io,resources=*,verbs=*
/////// Required permissions for controller
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;create;update
// +kubebuilder:rbac:groups=apps;extensions,resources=deployments;replicasets,verbs=*
// +kubebuilder:rbac:groups="",resources=pods;serviceaccounts;secrets;configmaps;persistentvolumeclaims,verbs=*
// +kubebuilder:rbac:groups="",resources=namespaces;events,verbs=get;list;watch
Expand All @@ -81,8 +82,7 @@ type DevWorkspaceReconciler struct {
// +kubebuilder:rbac:groups=apps;extensions,resources=deployments,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets,resourceNames=workspace-credentials-secret,verbs=get;create;delete

func (r *DevWorkspaceReconciler) Reconcile(req ctrl.Request) (reconcileResult ctrl.Result, err error) {
ctx := context.Background()
func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (reconcileResult ctrl.Result, err error) {
reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
clusterAPI := wsprovision.ClusterAPI{
Client: r.Client,
Expand Down Expand Up @@ -464,9 +464,8 @@ func getWorkspaceId(instance *dw.DevWorkspace) (string, error) {

// Mapping the pod to the devworkspace
func dwRelatedPodsHandler() handler.EventHandler {
podToDW := func(mapObj handler.MapObject) []reconcile.Request {
meta := mapObj.Meta
labels := meta.GetLabels()
podToDW := func(obj client.Object) []reconcile.Request {
labels := obj.GetLabels()
if _, ok := labels[constants.DevWorkspaceNameLabel]; !ok {
return nil
}
Expand All @@ -480,12 +479,12 @@ func dwRelatedPodsHandler() handler.EventHandler {
{
NamespacedName: types.NamespacedName{
Name: labels[constants.DevWorkspaceNameLabel],
Namespace: meta.GetNamespace(),
Namespace: obj.GetNamespace(),
},
},
}
}
return &handler.EnqueueRequestsFromMapFunc{ToRequests: handler.ToRequestsFunc(podToDW)}
return handler.EnqueueRequestsFromMapFunc(podToDW)
}

func (r *DevWorkspaceReconciler) SetupWithManager(mgr ctrl.Manager) error {
Expand Down
Loading