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

fix: adds missing CRDs for k8s EnvTest #584

Merged
merged 3 commits into from
Oct 2, 2023
Merged
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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,25 @@ help: ## Display this help.

##@ Development

define go-mod-version
$(shell go mod graph | grep $(1) | head -n 1 | cut -d'@' -f 2)
endef

# Using controller-gen to fetch external CRDs and put them in config/crd/external folder
# They're used in tests, as they have to be created for controller to work
define fetch-external-crds
GOFLAGS="-mod=readonly" $(CONTROLLER_GEN) crd \
paths=$(shell go env GOPATH)/pkg/mod/$(1)@$(call go-mod-version,$(1))/$(2)/... \
output:crd:artifacts:config=config/crd/external
endef

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
# TODO: enable below when we do webhook
# $(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
$(call fetch-external-crds,github.com/openshift/api,route/v1)
$(call fetch-external-crds,github.com/openshift/api,user/v1)

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
605 changes: 605 additions & 0 deletions config/crd/external/route.openshift.io_routes.yaml

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions config/crd/external/user.openshift.io_groups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: groups.user.openshift.io
spec:
group: user.openshift.io
names:
kind: Group
listKind: GroupList
plural: groups
singular: group
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: "Group represents a referenceable set of Users \n Compatibility
level 1: Stable within a major release for a minimum of 12 months or 3 minor
releases (whichever is longer)."
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
users:
description: Users is the list of users in this group.
items:
type: string
type: array
required:
- users
type: object
served: true
storage: true
97 changes: 97 additions & 0 deletions config/crd/external/user.openshift.io_identities.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: identities.user.openshift.io
spec:
group: user.openshift.io
names:
kind: Identity
listKind: IdentityList
plural: identities
singular: identity
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: "Identity records a successful authentication of a user with
an identity provider. The information about the source of authentication
is stored on the identity, and the identity is then associated with a single
user object. Multiple identities can reference a single user. Information
retrieved from the authentication provider is stored in the extra field
using a schema determined by the provider. \n Compatibility level 1: Stable
within a major release for a minimum of 12 months or 3 minor releases (whichever
is longer)."
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
extra:
additionalProperties:
type: string
description: Extra holds extra information about this identity
type: object
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
providerName:
description: ProviderName is the source of identity information
type: string
providerUserName:
description: ProviderUserName uniquely represents this identity in the
scope of the provider
type: string
user:
description: User is a reference to the user this identity is associated
with Both Name and UID must be set
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field access
statement, such as desiredState.manifest.containers[2]. For example,
if the object reference is to a container within a pod, this would
take on a value like: "spec.containers{name}" (where "name" refers
to the name of the container that triggered the event) or if no
container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined
way of referencing a part of an object. TODO: this design is not
final and this field is subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference is
made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
required:
- providerName
- providerUserName
- user
type: object
served: true
storage: true
111 changes: 111 additions & 0 deletions config/crd/external/user.openshift.io_useridentitymappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: useridentitymappings.user.openshift.io
spec:
group: user.openshift.io
names:
kind: UserIdentityMapping
listKind: UserIdentityMappingList
plural: useridentitymappings
singular: useridentitymapping
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: "UserIdentityMapping maps a user to an identity \n Compatibility
level 1: Stable within a major release for a minimum of 12 months or 3 minor
releases (whichever is longer)."
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
identity:
description: Identity is a reference to an identity
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field access
statement, such as desiredState.manifest.containers[2]. For example,
if the object reference is to a container within a pod, this would
take on a value like: "spec.containers{name}" (where "name" refers
to the name of the container that triggered the event) or if no
container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined
way of referencing a part of an object. TODO: this design is not
final and this field is subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference is
made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
user:
description: User is a reference to a user
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of an entire
object, this string should contain a valid JSON/Go field access
statement, such as desiredState.manifest.containers[2]. For example,
if the object reference is to a container within a pod, this would
take on a value like: "spec.containers{name}" (where "name" refers
to the name of the container that triggered the event) or if no
container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined
way of referencing a part of an object. TODO: this design is not
final and this field is subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference is
made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
type: object
served: true
storage: true
61 changes: 61 additions & 0 deletions config/crd/external/user.openshift.io_users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: users.user.openshift.io
spec:
group: user.openshift.io
names:
kind: User
listKind: UserList
plural: users
singular: user
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: "Upon log in, every user of the system receives a User and Identity
resource. Administrators may directly manipulate the attributes of the users
for their own tracking, or set groups via the API. The user name is unique
and is chosen based on the value provided by the identity provider - if
a user already exists with the incoming name, the user name may have a number
appended to it depending on the configuration of the system. \n Compatibility
level 1: Stable within a major release for a minimum of 12 months or 3 minor
releases (whichever is longer)."
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
fullName:
description: FullName is the full name of user
type: string
groups:
description: Groups specifies group names this user is a member of. This
field is deprecated and will be removed in a future release. Instead,
create a Group object containing the name of this User.
items:
type: string
type: array
identities:
description: Identities are the identities associated with this user
items:
type: string
type: array
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
required:
- groups
type: object
served: true
storage: true
6 changes: 3 additions & 3 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

// Check namespace
namespace := instance.Spec.ApplicationsNamespace
err = r.createOdhNamespace(instance, namespace, ctx)
err = r.createOdhNamespace(ctx, instance, namespace)
if err != nil {
// no need to log error as it was already logged in createOdhNamespace
return reconcile.Result{}, err
Expand Down Expand Up @@ -144,15 +144,15 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
} else {
// Apply self-managed rhods config
// Create rhods-admins Group if it doesn't exist
err := r.createUserGroup(instance, "rhods-admins", ctx)
err := r.createUserGroup(ctx, instance, "rhods-admins")
if err != nil {
return reconcile.Result{}, err
}
}
// Apply common rhods-specific config
} else { // ODH case
// Create odh-admins Group if it doesn't exist
err := r.createUserGroup(instance, "odh-admins", ctx)
err := r.createUserGroup(ctx, instance, "odh-admins")
if err != nil {
return reconcile.Result{}, err
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/dscinitialization/dscinitialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ var _ = Describe("DataScienceCluster initialization", func() {
Expect(foundMonitoringNamespace.Name).Should(Equal(monitoringNamespace))
})

It("Should create default network policy", func() {
// Currently commented out in the DSCI reconcile - setting test to Pending
PIt("Should create default network policy", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, otherwise the test will fail as the code for creating NetworkPolicy is commented out. PIt - marks test case as Pending in the execution report. You can also XIt - exclude it, and FIt - focus test suite to run only tests with F

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping that the comment one line above makes it clear :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, nice ! new things learnt every day

// then
foundNetworkPolicy := &netv1.NetworkPolicy{}
Eventually(objectExists(applicationNamespace, applicationNamespace, foundNetworkPolicy), timeout, interval).Should(BeTrue())
Expand Down
Loading