Repository: kubernetes-sigs/security-profiles-operator (c)

Issue:
pull-security-profiles-operator-verify failing intermittently
#### What happened:

Now that we have multiple CRDs `make verify-deployments` fails intermittently, therefore breaking `pull-security-profiles-operator-verify`. 

#### What you expected to happen:

On a clean git branch, `make verify-deployments` should yield consistent results.

#### How to reproduce it (as minimally and precisely as possible):

```
git fetch origin pull/176/head:test2
git checkout test2
make verify-deployments
git add .
git commit -m "test"
make verify-deployments
make verify-deployments
```

#### Anything else we need to know?:

Upon initial investigation the culprit seems to be:
```
go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen "crd:crdVersions=v1" paths="./api/..." output:crd:stdout > deploy/base/crd.yaml
```
As it yields results in different order every time.

#### Environment:

- Cloud provider or hardware configuration:
- OS (e.g: `cat /etc/os-release`): `Ubuntu 18.04`
- Kernel (e.g. `uname -a`): `Linux ... 5.4.0-58-generic #64-Ubuntu`
- Others:


Pull request:
Reorganize CRD type definitions
controller-gen is nondeterministic about the order in which it generates
YAML manifests from Go types, so `make manifests` may put them in a
different order and cause unnecessary changes to the generated YAML
files. The code is growing to a point that a little reorganization is
nice anyway. This change splits the types into their own packages so
that the Makefile command can have more fine-grained control over which
types to generate in which order.

<!--  Thanks for sending a pull request!  Here are some tips for you:

- If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
- Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
- If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
- If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

#### What type of PR is this?

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind design

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->
/kind bug
/kind failing-test

#### What this PR does / why we need it:

#### Which issue(s) this PR fixes:

<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.

Fixes #

or

None
-->
Fixes #177 

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note
The `sigs.k8s.io/security-profiles-operator/api/v1alpha1` package which defined the `SeccompProfile` and `SelinuxPolicy` types was split into two packages, `sigs.k8s.io/security-profiles-operator/api/seccompprofile/v1alpha1` and `sigs.k8s.io/security-profiles-operator/api/selinuxpolicy/v1alpha1` and must be imported separately.
```


Patch:
diff --git a/Makefile b/Makefile
index 317a9eda3..8af65a7fb 100644
--- a/Makefile
+++ b/Makefile
@@ -149,9 +149,10 @@ test-unit: $(BUILD_DIR) ## Run the unit tests
 test-e2e: ## Run the end-to-end tests
 	$(GO) test -timeout 40m -count=1 ./test/... -v
 
-# Generate CRD manifest
+# Generate CRD manifests
 manifests:
-	$(GO) run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen $(CRD_OPTIONS) paths="./api/..." output:crd:stdout > deploy/base/crd.yaml
+	$(GO) run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen $(CRD_OPTIONS) paths="./api/seccompprofile/..." output:crd:stdout > deploy/base/crd.yaml
+	$(GO) run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen $(CRD_OPTIONS) paths="./api/selinuxpolicy/..." output:crd:stdout >> deploy/base/crd.yaml
 
 # Generate deepcopy code
 generate:
diff --git a/api/v1alpha1/groupversion_info.go b/api/seccompprofile/v1alpha1/groupversion_info.go
similarity index 100%
rename from api/v1alpha1/groupversion_info.go
rename to api/seccompprofile/v1alpha1/groupversion_info.go
diff --git a/api/v1alpha1/seccompprofile_types.go b/api/seccompprofile/v1alpha1/seccompprofile_types.go
similarity index 100%
rename from api/v1alpha1/seccompprofile_types.go
rename to api/seccompprofile/v1alpha1/seccompprofile_types.go
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/seccompprofile/v1alpha1/zz_generated.deepcopy.go
similarity index 67%
rename from api/v1alpha1/zz_generated.deepcopy.go
rename to api/seccompprofile/v1alpha1/zz_generated.deepcopy.go
index 1170f4c5d..bcf65b3cd 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/seccompprofile/v1alpha1/zz_generated.deepcopy.go
@@ -166,95 +166,6 @@ func (in *SeccompProfileStatus) DeepCopy() *SeccompProfileStatus {
 	return out
 }
 
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *SelinuxPolicy) DeepCopyInto(out *SelinuxPolicy) {
-	*out = *in
-	out.TypeMeta = in.TypeMeta
-	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
-	out.Spec = in.Spec
-	out.Status = in.Status
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicy.
-func (in *SelinuxPolicy) DeepCopy() *SelinuxPolicy {
-	if in == nil {
-		return nil
-	}
-	out := new(SelinuxPolicy)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
-func (in *SelinuxPolicy) DeepCopyObject() runtime.Object {
-	if c := in.DeepCopy(); c != nil {
-		return c
-	}
-	return nil
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *SelinuxPolicyList) DeepCopyInto(out *SelinuxPolicyList) {
-	*out = *in
-	out.TypeMeta = in.TypeMeta
-	in.ListMeta.DeepCopyInto(&out.ListMeta)
-	if in.Items != nil {
-		in, out := &in.Items, &out.Items
-		*out = make([]SelinuxPolicy, len(*in))
-		for i := range *in {
-			(*in)[i].DeepCopyInto(&(*out)[i])
-		}
-	}
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicyList.
-func (in *SelinuxPolicyList) DeepCopy() *SelinuxPolicyList {
-	if in == nil {
-		return nil
-	}
-	out := new(SelinuxPolicyList)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
-func (in *SelinuxPolicyList) DeepCopyObject() runtime.Object {
-	if c := in.DeepCopy(); c != nil {
-		return c
-	}
-	return nil
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *SelinuxPolicySpec) DeepCopyInto(out *SelinuxPolicySpec) {
-	*out = *in
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicySpec.
-func (in *SelinuxPolicySpec) DeepCopy() *SelinuxPolicySpec {
-	if in == nil {
-		return nil
-	}
-	out := new(SelinuxPolicySpec)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *SelinuxPolicyStatus) DeepCopyInto(out *SelinuxPolicyStatus) {
-	*out = *in
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicyStatus.
-func (in *SelinuxPolicyStatus) DeepCopy() *SelinuxPolicyStatus {
-	if in == nil {
-		return nil
-	}
-	out := new(SelinuxPolicyStatus)
-	in.DeepCopyInto(out)
-	return out
-}
-
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *Syscall) DeepCopyInto(out *Syscall) {
 	*out = *in
diff --git a/api/selinuxpolicy/v1alpha1/groupversion_info.go b/api/selinuxpolicy/v1alpha1/groupversion_info.go
new file mode 100644
index 000000000..caf51e785
--- /dev/null
+++ b/api/selinuxpolicy/v1alpha1/groupversion_info.go
@@ -0,0 +1,36 @@
+/*
+Copyright 2020 The Kubernetes Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Package v1alpha1 contains API Schema definitions for the security-profiles-operator v1alpha1 API group
+// +kubebuilder:object:generate=true
+// +groupName=security-profiles-operator.x-k8s.io
+package v1alpha1
+
+import (
+	"k8s.io/apimachinery/pkg/runtime/schema"
+	"sigs.k8s.io/controller-runtime/pkg/scheme"
+)
+
+var (
+	// GroupVersion is group version used to register these objects.
+	GroupVersion = schema.GroupVersion{Group: "security-profiles-operator.x-k8s.io", Version: "v1alpha1"}
+
+	// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
+	SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
+
+	// AddToScheme adds the types in this group-version to the given scheme.
+	AddToScheme = SchemeBuilder.AddToScheme
+)
diff --git a/api/v1alpha1/selinuxpolicy_types.go b/api/selinuxpolicy/v1alpha1/selinuxpolicy_types.go
similarity index 100%
rename from api/v1alpha1/selinuxpolicy_types.go
rename to api/selinuxpolicy/v1alpha1/selinuxpolicy_types.go
diff --git a/api/selinuxpolicy/v1alpha1/zz_generated.deepcopy.go b/api/selinuxpolicy/v1alpha1/zz_generated.deepcopy.go
new file mode 100644
index 000000000..3255eda16
--- /dev/null
+++ b/api/selinuxpolicy/v1alpha1/zz_generated.deepcopy.go
@@ -0,0 +1,115 @@
+// +build !ignore_autogenerated
+
+/*
+Copyright 2020 The Kubernetes Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Code generated by controller-gen. DO NOT EDIT.
+
+package v1alpha1
+
+import (
+	runtime "k8s.io/apimachinery/pkg/runtime"
+)
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *SelinuxPolicy) DeepCopyInto(out *SelinuxPolicy) {
+	*out = *in
+	out.TypeMeta = in.TypeMeta
+	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
+	out.Spec = in.Spec
+	in.Status.DeepCopyInto(&out.Status)
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicy.
+func (in *SelinuxPolicy) DeepCopy() *SelinuxPolicy {
+	if in == nil {
+		return nil
+	}
+	out := new(SelinuxPolicy)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *SelinuxPolicy) DeepCopyObject() runtime.Object {
+	if c := in.DeepCopy(); c != nil {
+		return c
+	}
+	return nil
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *SelinuxPolicyList) DeepCopyInto(out *SelinuxPolicyList) {
+	*out = *in
+	out.TypeMeta = in.TypeMeta
+	in.ListMeta.DeepCopyInto(&out.ListMeta)
+	if in.Items != nil {
+		in, out := &in.Items, &out.Items
+		*out = make([]SelinuxPolicy, len(*in))
+		for i := range *in {
+			(*in)[i].DeepCopyInto(&(*out)[i])
+		}
+	}
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicyList.
+func (in *SelinuxPolicyList) DeepCopy() *SelinuxPolicyList {
+	if in == nil {
+		return nil
+	}
+	out := new(SelinuxPolicyList)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *SelinuxPolicyList) DeepCopyObject() runtime.Object {
+	if c := in.DeepCopy(); c != nil {
+		return c
+	}
+	return nil
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *SelinuxPolicySpec) DeepCopyInto(out *SelinuxPolicySpec) {
+	*out = *in
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicySpec.
+func (in *SelinuxPolicySpec) DeepCopy() *SelinuxPolicySpec {
+	if in == nil {
+		return nil
+	}
+	out := new(SelinuxPolicySpec)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *SelinuxPolicyStatus) DeepCopyInto(out *SelinuxPolicyStatus) {
+	*out = *in
+	in.ConditionedStatus.DeepCopyInto(&out.ConditionedStatus)
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelinuxPolicyStatus.
+func (in *SelinuxPolicyStatus) DeepCopy() *SelinuxPolicyStatus {
+	if in == nil {
+		return nil
+	}
+	out := new(SelinuxPolicyStatus)
+	in.DeepCopyInto(out)
+	return out
+}
diff --git a/cmd/security-profiles-operator/main.go b/cmd/security-profiles-operator/main.go
index 02e075b9a..cc9f4517e 100644
--- a/cmd/security-profiles-operator/main.go
+++ b/cmd/security-profiles-operator/main.go
@@ -26,7 +26,8 @@ import (
 	ctrl "sigs.k8s.io/controller-runtime"
 	"sigs.k8s.io/controller-runtime/pkg/manager"
 
-	"sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	seccompprofilev1alpha1 "sigs.k8s.io/security-profiles-operator/api/seccompprofile/v1alpha1"
+	selinuxpolicyv1alpha1 "sigs.k8s.io/security-profiles-operator/api/selinuxpolicy/v1alpha1"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/config"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/controllers/profile"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/controllers/selinuxpolicy"
@@ -123,7 +124,7 @@ func run(ctx *cli.Context) error {
 			fatalErrors <- errors.Wrap(err, "create manager")
 		}
 
-		if err := v1alpha1.AddToScheme(mgr.GetScheme()); err != nil {
+		if err := seccompprofilev1alpha1.AddToScheme(mgr.GetScheme()); err != nil {
 			fatalErrors <- errors.Wrap(err, "add core operator APIs to scheme")
 		}
 
@@ -154,7 +155,7 @@ func run(ctx *cli.Context) error {
 			fatalErrors <- errors.Wrap(err, "create cluster manager")
 		}
 
-		if err := v1alpha1.AddToScheme(mgr.GetScheme()); err != nil {
+		if err := selinuxpolicyv1alpha1.AddToScheme(mgr.GetScheme()); err != nil {
 			fatalErrors <- errors.Wrap(err, "add core operator APIs to scheme")
 		}
 
diff --git a/internal/pkg/controllers/profile/profile.go b/internal/pkg/controllers/profile/profile.go
index 5caad9a4c..bd62f4ce4 100644
--- a/internal/pkg/controllers/profile/profile.go
+++ b/internal/pkg/controllers/profile/profile.go
@@ -41,7 +41,7 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
 	"sigs.k8s.io/controller-runtime/pkg/reconcile"
 
-	"sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	"sigs.k8s.io/security-profiles-operator/api/seccompprofile/v1alpha1"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/config"
 )
 
diff --git a/internal/pkg/controllers/selinuxpolicy/configmap_controller.go b/internal/pkg/controllers/selinuxpolicy/configmap_controller.go
index 09f3c929b..abf720478 100644
--- a/internal/pkg/controllers/selinuxpolicy/configmap_controller.go
+++ b/internal/pkg/controllers/selinuxpolicy/configmap_controller.go
@@ -34,7 +34,7 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
 	"sigs.k8s.io/controller-runtime/pkg/reconcile"
 
-	spov1alpha1 "sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	spov1alpha1 "sigs.k8s.io/security-profiles-operator/api/selinuxpolicy/v1alpha1"
 )
 
 // blank assignment to verify that ReconcileConfigMap implements `reconcile.Reconciler`.
diff --git a/internal/pkg/controllers/selinuxpolicy/selinuxpolicy_controller.go b/internal/pkg/controllers/selinuxpolicy/selinuxpolicy_controller.go
index acac260c2..a90802890 100644
--- a/internal/pkg/controllers/selinuxpolicy/selinuxpolicy_controller.go
+++ b/internal/pkg/controllers/selinuxpolicy/selinuxpolicy_controller.go
@@ -34,7 +34,7 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/client"
 	"sigs.k8s.io/controller-runtime/pkg/reconcile"
 
-	spov1alpha1 "sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	spov1alpha1 "sigs.k8s.io/security-profiles-operator/api/selinuxpolicy/v1alpha1"
 )
 
 // The underscore is not a valid character in a pod, so we can
diff --git a/internal/pkg/controllers/selinuxpolicy/setup.go b/internal/pkg/controllers/selinuxpolicy/setup.go
index 2ab13b10d..3bf16199e 100644
--- a/internal/pkg/controllers/selinuxpolicy/setup.go
+++ b/internal/pkg/controllers/selinuxpolicy/setup.go
@@ -29,7 +29,7 @@ import (
 	ctrl "sigs.k8s.io/controller-runtime"
 	logf "sigs.k8s.io/controller-runtime/pkg/log"
 
-	spov1alpha1 "sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	spov1alpha1 "sigs.k8s.io/security-profiles-operator/api/selinuxpolicy/v1alpha1"
 )
 
 var log = logf.Log.WithName("selinuxpolicy")


Test patch:
diff --git a/internal/pkg/controllers/profile/profile_test.go b/internal/pkg/controllers/profile/profile_test.go
index 2e1c9a89d..0fe1e9e95 100644
--- a/internal/pkg/controllers/profile/profile_test.go
+++ b/internal/pkg/controllers/profile/profile_test.go
@@ -36,7 +36,7 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/log"
 	"sigs.k8s.io/controller-runtime/pkg/reconcile"
 
-	"sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	"sigs.k8s.io/security-profiles-operator/api/seccompprofile/v1alpha1"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/config"
 )
 
diff --git a/test/e2e_test.go b/test/e2e_test.go
index e0a348b25..b0d28a25b 100644
--- a/test/e2e_test.go
+++ b/test/e2e_test.go
@@ -23,7 +23,7 @@ import (
 	"os"
 	"strings"
 
-	"sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	"sigs.k8s.io/security-profiles-operator/api/seccompprofile/v1alpha1"
 )
 
 const (
diff --git a/test/tc_default_profiles_test.go b/test/tc_default_profiles_test.go
index 03f9d9b71..9aa791484 100644
--- a/test/tc_default_profiles_test.go
+++ b/test/tc_default_profiles_test.go
@@ -22,7 +22,7 @@ import (
 
 	v1 "k8s.io/api/core/v1"
 
-	v1alpha1 "sigs.k8s.io/security-profiles-operator/api/v1alpha1"
+	"sigs.k8s.io/security-profiles-operator/api/seccompprofile/v1alpha1"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/config"
 	"sigs.k8s.io/security-profiles-operator/internal/pkg/controllers/profile"
 )