Skip to content

Commit 1f427b8

Browse files
Merge pull request #318 from sabre1041/exclude-invalid-names
Support for excluding invalid group names
2 parents d0c36e9 + d68841a commit 1f427b8

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
7979
# example.com/memcached-operator-bundle:$VERSION and example.com/memcached-operator-catalog:$VERSION.
8080
IMAGE_TAG_BASE ?= quay.io/redhat-cop/$(OPERATOR_NAME)
8181

82+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
83+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
84+
85+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
86+
# You can enable this value if you would like to use SHA Based Digests
87+
# To enable set flag to true
88+
USE_IMAGE_DIGESTS ?= false
89+
ifeq ($(USE_IMAGE_DIGESTS), true)
90+
BUNDLE_GEN_FLAGS += --use-image-digests
91+
endif
92+
8293
# BUNDLE_IMG defines the image:tag used for the bundle.
8394
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
8495
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)

api/v1alpha1/groupsync_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ type GroupSyncSpec struct {
4646
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Schedule",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
4747
// +kubebuilder:validation:Optional
4848
Schedule string `json:"schedule,omitempty"`
49+
50+
// ExcludeInvalidGroupNames excludes Groups with names that are not RFC 1035 compliant.
51+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Exclude Invalid Group Names",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
52+
// +kubebuilder:validation:Optional
53+
ExcludeInvalidGroupNames bool `json:"excludeInvalidGroupNames,omitempty"`
4954
}
5055

5156
// GroupSyncStatus defines the observed state of GroupSync

config/crd/bases/redhatcop.redhat.io_groupsyncs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ spec:
3131
spec:
3232
description: GroupSyncSpec defines the desired state of GroupSync
3333
properties:
34+
excludeInvalidGroupNames:
35+
description: ExcludeInvalidGroupNames excludes Groups with names that are not RFC 1035 compliant.
36+
type: boolean
3437
providers:
3538
description: List of Providers that can be mounted by containers belonging to the pod.
3639
items:

config/manifests/bases/group-sync-operator.clusterserviceversion.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ spec:
3333
kind: GroupSync
3434
name: groupsyncs.redhatcop.redhat.io
3535
specDescriptors:
36+
- description: ExcludeInvalidGroupNames excludes Groups with names that are
37+
not RFC 1035 compliant.
38+
displayName: Exclude Invalid Group Names
39+
path: excludeInvalidGroupNames
40+
x-descriptors:
41+
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
3642
- description: List of Providers that can be mounted by containers belonging
3743
to the pod.
3844
displayName: Providers
@@ -721,7 +727,7 @@ spec:
721727
displayName: Last Sync Success Time
722728
path: lastSyncSuccessTime
723729
version: v1alpha1
724-
description: |-
730+
description: |
725731
Synchronizes groups from external providers into OpenShift
726732
727733
## Overview
@@ -881,7 +887,7 @@ spec:
881887
882888
```shell
883889
oc create secret generic gitlab-group-sync --from-literal=token=<token> --from-literal=tokenType=personal
884-
```
890+
```
885891
886892
The following keys are required for username and password:
887893

controllers/groupsync_controller.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223
"time"
2324

2425
"github.com/go-logr/logr"
@@ -32,6 +33,7 @@ import (
3233
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3334
"k8s.io/apimachinery/pkg/types"
3435
utilerrors "k8s.io/apimachinery/pkg/util/errors"
36+
apimachineryvalidation "k8s.io/apimachinery/pkg/util/validation"
3537
kubeclock "k8s.io/utils/clock"
3638
ctrl "sigs.k8s.io/controller-runtime"
3739
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -125,6 +127,15 @@ func (r *GroupSyncReconciler) Reconcile(context context.Context, req ctrl.Reques
125127

126128
for i, group := range groups {
127129

130+
// Verify valid Group Names
131+
if instance.Spec.ExcludeInvalidGroupNames {
132+
msgs := apimachineryvalidation.IsDNS1035Label(group.Name)
133+
if len(msgs) > 0 {
134+
r.Log.Info(fmt.Sprintf("Group '%s' contains invalid name: %s", group.Name, strings.Join(msgs, ",")))
135+
continue
136+
}
137+
}
138+
128139
ocpGroup := &userv1.Group{}
129140
err := r.GetClient().Get(context, types.NamespacedName{Name: group.Name, Namespace: ""}, ocpGroup)
130141

0 commit comments

Comments
 (0)