Skip to content

Commit

Permalink
Merge pull request #34 from sacharya/v1beta
Browse files Browse the repository at this point in the history
Update API version to v1beta1
  • Loading branch information
openshift-merge-robot authored May 5, 2020
2 parents 696e4f9 + 58a04d2 commit 132d5cb
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 78 deletions.
10 changes: 2 additions & 8 deletions deploy/crds/cincinnati.openshift.io_cincinnatis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ spec:
spec:
description: CincinnatiSpec defines the desired state of Cincinnati
properties:
certConfigMapKey:
description: CertConfigMapKey refers to the ConfigMap key that holds
a CA cert to the registry Cincinnati will contact to build the upgrade
graph. The name of the ConfigMap holding the key comes from the field
additionalTrustedCA in the image.config.openshift.io API.
type: string
graphDataImage:
description: GraphDataImage is a container image that contains the Cincinnati
graph data. The data is copied to /var/lib/cincinnati/graph-data.
Expand Down Expand Up @@ -93,8 +87,8 @@ spec:
type: array
type: object
type: object
version: v1alpha1
version: v1beta1
versions:
- name: v1alpha1
- name: v1beta1
served: true
storage: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: cincinnati.openshift.io/v1alpha1
apiVersion: cincinnati.openshift.io/v1beta1
kind: Cincinnati
metadata:
name: example-cincinnati
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: operators.coreos.com/v1alpha1
apiVersion: operators.coreos.com/v1beta1
kind: ClusterServiceVersion
metadata:
annotations:
alm-examples: |-
[
{
"apiVersion": "cincinnati.openshift.io/v1alpha1",
"apiVersion": "cincinnati.openshift.io/v1beta1",
"kind": "Cincinnati",
"metadata": {
"name": "cincinnati-instance"
Expand Down Expand Up @@ -34,7 +34,7 @@ spec:
- description: Cincinnati is the Schema for a Cincinnati service.
kind: Cincinnati
name: cincinnatis.cincinnati.openshift.io
version: v1alpha1
version: v1beta1
description: |-
# Use Case
Running a Cincinnati instance in a cluster is appealing for offline OpenShift
Expand Down
2 changes: 1 addition & 1 deletion docs/graph-data-init-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ container image.

For the example above:
```
apiVersion: cincinnati.openshift.io/v1alpha1
apiVersion: cincinnati.openshift.io/v1beta1
kind: Cincinnati
metadata:
name: example-cincinnati
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package apis

import (
"github.com/openshift/cincinnati-operator/pkg/apis/cincinnati/v1alpha1"
"github.com/openshift/cincinnati-operator/pkg/apis/cincinnati/v1beta1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme)
}
4 changes: 0 additions & 4 deletions pkg/apis/cincinnati/v1alpha1/doc.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alpha1
package v1beta1

import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/cincinnati/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1beta1 contains API Schema definitions for the cincinnati v1beta1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=cincinnati.openshift.io
package v1beta1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// NOTE: Boilerplate only. Ignore this file.

// Package v1alpha1 contains API Schema definitions for the cincinnati v1alpha1 API group
// Package v1beta1 contains API Schema definitions for the cincinnati v1beta1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=cincinnati.openshift.io
package v1alpha1
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -12,7 +12,7 @@ import (

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "cincinnati.openshift.io", Version: "v1alpha1"}
SchemeGroupVersion = schema.GroupVersion{Group: "cincinnati.openshift.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This file was autogenerated by openapi-gen. Do not edit it manually!

package v1alpha1
package v1beta1

import (
common "k8s.io/kube-openapi/pkg/common"
Expand Down
34 changes: 17 additions & 17 deletions pkg/controller/cincinnati/cincinnati_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

apicfgv1 "github.com/openshift/api/config/v1"
cv1alpha1 "github.com/openshift/cincinnati-operator/pkg/apis/cincinnati/v1alpha1"
cv1beta1 "github.com/openshift/cincinnati-operator/pkg/apis/cincinnati/v1beta1"
"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
)

Expand Down Expand Up @@ -60,7 +60,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to primary resource Cincinnati
err = c.Watch(&source.Kind{Type: &cv1alpha1.Cincinnati{}}, &handler.EnqueueRequestForObject{})
err = c.Watch(&source.Kind{Type: &cv1beta1.Cincinnati{}}, &handler.EnqueueRequestForObject{})
if err != nil {
return err
}
Expand All @@ -74,7 +74,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
} {
err = c.Watch(&source.Kind{Type: obj}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &cv1alpha1.Cincinnati{},
OwnerType: &cv1beta1.Cincinnati{},
})
if err != nil {
return err
Expand All @@ -93,7 +93,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
//Watch for all ConfigMap changes, only Reconcile when name == Image.Spec.AdditionalTrustedCA.Name
err = c.Watch(&source.Kind{Type: &corev1.ConfigMap{}},
&handler.EnqueueRequestsFromMapFunc{ToRequests: &mapper{mgr.GetClient()}},
predicate.GenerationChangedPredicate{})
)
if err != nil {
log.Error(err, "Error watching ConfigMap API")
return err
Expand Down Expand Up @@ -122,7 +122,7 @@ func (r *ReconcileCincinnati) Reconcile(request reconcile.Request) (reconcile.Re
reqLogger.Info("Reconciling Cincinnati")

// Fetch the Cincinnati instance
instance := &cv1alpha1.Cincinnati{}
instance := &cv1beta1.Cincinnati{}
err := r.client.Get(ctx, request.NamespacedName, instance)
if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -135,7 +135,7 @@ func (r *ReconcileCincinnati) Reconcile(request reconcile.Request) (reconcile.Re
}

instanceCopy := instance.DeepCopy()
instanceCopy.Status = cv1alpha1.CincinnatiStatus{}
instanceCopy.Status = cv1beta1.CincinnatiStatus{}

// this object creates all the kube resources we need and then holds them as
// the canonical reference for those resources during reconciliation.
Expand All @@ -145,7 +145,7 @@ func (r *ReconcileCincinnati) Reconcile(request reconcile.Request) (reconcile.Re
return reconcile.Result{}, err
}

for _, f := range []func(context.Context, logr.Logger, *cv1alpha1.Cincinnati, *kubeResources) error{
for _, f := range []func(context.Context, logr.Logger, *cv1beta1.Cincinnati, *kubeResources) error{
r.ensureConfig,
r.ensureEnvConfig,
r.ensureAdditionalTrustedCA,
Expand All @@ -167,7 +167,7 @@ func (r *ReconcileCincinnati) Reconcile(request reconcile.Request) (reconcile.Re
// appropriate.
if err == nil {
conditionsv1.SetStatusCondition(&instanceCopy.Status.Conditions, conditionsv1.Condition{
Type: cv1alpha1.ConditionReconcileCompleted,
Type: cv1beta1.ConditionReconcileCompleted,
Status: corev1.ConditionTrue,
Reason: "Success",
Message: "",
Expand All @@ -182,17 +182,17 @@ func (r *ReconcileCincinnati) Reconcile(request reconcile.Request) (reconcile.Re
}

// handleErr logs the error and sets an appropriate Condition on the status.
func handleErr(reqLogger logr.Logger, status *cv1alpha1.CincinnatiStatus, reason string, e error) {
func handleErr(reqLogger logr.Logger, status *cv1beta1.CincinnatiStatus, reason string, e error) {
conditionsv1.SetStatusCondition(&status.Conditions, conditionsv1.Condition{
Type: cv1alpha1.ConditionReconcileCompleted,
Type: cv1beta1.ConditionReconcileCompleted,
Status: corev1.ConditionFalse,
Reason: reason,
Message: e.Error(),
})
reqLogger.Error(e, reason)
}

func (r *ReconcileCincinnati) ensureAdditionalTrustedCA(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensureAdditionalTrustedCA(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
// Check if the Cluster is aware of a registry requiring an
// AdditionalTrustedCA
image := &apicfgv1.Image{}
Expand Down Expand Up @@ -247,7 +247,7 @@ func (r *ReconcileCincinnati) ensureAdditionalTrustedCA(ctx context.Context, req
return nil
}

func (r *ReconcileCincinnati) ensureDeployment(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensureDeployment(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
deployment := resources.deployment
if err := controllerutil.SetControllerReference(instance, deployment, r.scheme); err != nil {
return err
Expand Down Expand Up @@ -347,7 +347,7 @@ func (r *ReconcileCincinnati) ensureDeployment(ctx context.Context, reqLogger lo
return nil
}

func (r *ReconcileCincinnati) ensurePodDisruptionBudget(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensurePodDisruptionBudget(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
pdb := resources.podDisruptionBudget
// Set Cincinnati instance as the owner and controller
if err := controllerutil.SetControllerReference(instance, pdb, r.scheme); err != nil {
Expand Down Expand Up @@ -382,7 +382,7 @@ func (r *ReconcileCincinnati) ensurePodDisruptionBudget(ctx context.Context, req
return nil
}

func (r *ReconcileCincinnati) ensureConfig(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensureConfig(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
config := resources.graphBuilderConfig
// Set Cincinnati instance as the owner and controller
if err := controllerutil.SetControllerReference(instance, config, r.scheme); err != nil {
Expand All @@ -396,7 +396,7 @@ func (r *ReconcileCincinnati) ensureConfig(ctx context.Context, reqLogger logr.L
return nil
}

func (r *ReconcileCincinnati) ensureEnvConfig(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensureEnvConfig(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
config := resources.envConfig
// Set Cincinnati instance as the owner and controller
if err := controllerutil.SetControllerReference(instance, config, r.scheme); err != nil {
Expand All @@ -410,7 +410,7 @@ func (r *ReconcileCincinnati) ensureEnvConfig(ctx context.Context, reqLogger log
return nil
}

func (r *ReconcileCincinnati) ensureGraphBuilderService(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensureGraphBuilderService(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
service := resources.graphBuilderService
// Set Cincinnati instance as the owner and controller
if err := controllerutil.SetControllerReference(instance, service, r.scheme); err != nil {
Expand All @@ -424,7 +424,7 @@ func (r *ReconcileCincinnati) ensureGraphBuilderService(ctx context.Context, req
return nil
}

func (r *ReconcileCincinnati) ensurePolicyEngineService(ctx context.Context, reqLogger logr.Logger, instance *cv1alpha1.Cincinnati, resources *kubeResources) error {
func (r *ReconcileCincinnati) ensurePolicyEngineService(ctx context.Context, reqLogger logr.Logger, instance *cv1beta1.Cincinnati, resources *kubeResources) error {
service := resources.policyEngineService
// Set Cincinnati instance as the owner and controller
if err := controllerutil.SetControllerReference(instance, service, r.scheme); err != nil {
Expand Down
28 changes: 14 additions & 14 deletions pkg/controller/cincinnati/cincinnati_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/cincinnati-operator/pkg/apis"
cv1alpha1 "github.com/openshift/cincinnati-operator/pkg/apis/cincinnati/v1alpha1"
cv1beta1 "github.com/openshift/cincinnati-operator/pkg/apis/cincinnati/v1beta1"
"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -56,15 +56,15 @@ func TestMain(m *testing.M) {
func TestReconcileComplete(t *testing.T) {
tests := []struct {
name string
cincinnati *cv1alpha1.Cincinnati
cincinnati *cv1beta1.Cincinnati
expectedConditions []conditionsv1.Condition
}{
{
name: "Reconcile",
cincinnati: newDefaultCincinnati(),
expectedConditions: []conditionsv1.Condition{
{
Type: cv1alpha1.ConditionReconcileCompleted,
Type: cv1beta1.ConditionReconcileCompleted,
Status: corev1.ConditionTrue,
},
},
Expand All @@ -80,7 +80,7 @@ func TestReconcileComplete(t *testing.T) {
if err != nil {
t.Fatal(err)
}
instance := &cv1alpha1.Cincinnati{}
instance := &cv1beta1.Cincinnati{}
err = r.client.Get(context.TODO(), request.NamespacedName, instance)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestEnsureAdditionalTrustedCA(t *testing.T) {
func TestEnsureDeployment(t *testing.T) {
tests := []struct {
name string
cincinnati *cv1alpha1.Cincinnati
cincinnati *cv1beta1.Cincinnati
caCert bool
}{
{
Expand All @@ -209,7 +209,7 @@ func TestEnsureDeployment(t *testing.T) {
},
{
name: "EnsureDeploymentWithGraphDataImage",
cincinnati: func() *cv1alpha1.Cincinnati {
cincinnati: func() *cv1beta1.Cincinnati {
cincinnati := newDefaultCincinnati()
cincinnati.Spec.GraphDataImage = testGraphDataImage
return cincinnati
Expand Down Expand Up @@ -311,15 +311,15 @@ func TestEnsurePolicyEngineService(t *testing.T) {
func TestEnsurePodDisruptionBudget(t *testing.T) {
tests := []struct {
name string
cincinnati *cv1alpha1.Cincinnati
cincinnati *cv1beta1.Cincinnati
}{
{
name: "EnsurePodDisruptionBudgetReplicas1",
cincinnati: newDefaultCincinnati(),
},
{
name: "EnsurePodDisruptionBudgetReplicas10",
cincinnati: func() *cv1alpha1.Cincinnati {
cincinnati: func() *cv1beta1.Cincinnati {
cincinnati := newDefaultCincinnati()
cincinnati.Spec.Replicas = 10
return cincinnati
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestEnsurePodDisruptionBudget(t *testing.T) {
}
}

func newRequest(cincinnati *cv1alpha1.Cincinnati) reconcile.Request {
func newRequest(cincinnati *cv1beta1.Cincinnati) reconcile.Request {
namespacedName := types.NamespacedName{
Namespace: cincinnati.ObjectMeta.Namespace,
Name: cincinnati.ObjectMeta.Name,
Expand All @@ -368,8 +368,8 @@ func newTestReconciler(initObjs ...runtime.Object) *ReconcileCincinnati {
}
}

func newDefaultCincinnati() *cv1alpha1.Cincinnati {
return &cv1alpha1.Cincinnati{
func newDefaultCincinnati() *cv1beta1.Cincinnati {
return &cv1beta1.Cincinnati{
TypeMeta: metav1.TypeMeta{
Kind: testCincinnatiKind,
APIVersion: testCincinnatiAPIVersion,
Expand All @@ -378,7 +378,7 @@ func newDefaultCincinnati() *cv1alpha1.Cincinnati {
Name: testName,
Namespace: testNamespace,
},
Spec: cv1alpha1.CincinnatiSpec{
Spec: cv1beta1.CincinnatiSpec{
Replicas: testReplicas,
Registry: testRegistry,
Repository: testRepository,
Expand Down Expand Up @@ -412,14 +412,14 @@ func newConfigMap() *corev1.ConfigMap {
}
}

func verifyConditions(t *testing.T, expectedConditions []conditionsv1.Condition, cincinnati *cv1alpha1.Cincinnati) {
func verifyConditions(t *testing.T, expectedConditions []conditionsv1.Condition, cincinnati *cv1beta1.Cincinnati) {
for _, condition := range expectedConditions {
assert.True(t, conditionsv1.IsStatusConditionPresentAndEqual(cincinnati.Status.Conditions, condition.Type, condition.Status))
}
assert.Equal(t, len(expectedConditions), len(cincinnati.Status.Conditions))
}

func verifyOwnerReference(t *testing.T, ownerReference metav1.OwnerReference, cincinnati *cv1alpha1.Cincinnati) {
func verifyOwnerReference(t *testing.T, ownerReference metav1.OwnerReference, cincinnati *cv1beta1.Cincinnati) {
assert.Equal(t, ownerReference.Name, cincinnati.Name)
//Note: These properties seem to be derived from runtime object and do not seem to match the expected values.
//assert.Equal(t, ownerReference.Kind, cincinnati.Kind)
Expand Down
Loading

0 comments on commit 132d5cb

Please sign in to comment.