Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cincinnati-operator

This operator is developed using the [operator SDK][operator-sdk], version 0.16.
This operator is developed using the [operator SDK][operator-sdk], version 0.18.
Installation docs are [here][operator-sdk-installation].

## Run locally
Expand Down Expand Up @@ -49,4 +49,4 @@ make unit-test
```

[operator-sdk]: https://sdk.operatorframework.io/docs/
[operator-sdk-installation]: https://sdk.operatorframework.io/docs/install-operator-sdk/
[operator-sdk-installation]: https://v0-18-x.sdk.operatorframework.io/docs/install-operator-sdk/
166 changes: 81 additions & 85 deletions deploy/crds/cincinnati.openshift.io_cincinnatis_crd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: cincinnatis.cincinnati.openshift.io
Expand All @@ -10,91 +10,87 @@ spec:
plural: cincinnatis
singular: cincinnati
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: Cincinnati is the Schema for a Cincinnati service.
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:
description: 'metadata is standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata'
type: object
spec:
description: spec is the desired state of the Cincinnati service. The operator
will work to ensure that the desired configuration is applied to the cluster.
properties:
graphDataImage:
description: graphDataImage is a container image that contains the Cincinnati
graph data.
type: string
registry:
description: registry is the container registry to use, such as "quay.io".
type: string
replicas:
description: replicas is the number of pods to run. When >=2, a PodDisruptionBudget
will ensure that voluntary disruption leaves at least one Pod running
at all times.
format: int32
minimum: 1
type: integer
repository:
description: repository is the repository to use in the Registry, such
as "openshift-release-dev/ocp-release"
type: string
required:
- graphDataImage
- registry
- replicas
- repository
type: object
status:
description: status contains information about the current state of the
Cincinnati service.
properties:
conditions:
description: Conditions describe the state of the Cincinnati resource.
items:
description: Condition represents the state of the operator's reconciliation
functionality.
properties:
lastHeartbeatTime:
format: date-time
type: string
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
description: ConditionType is the state of the operator's reconciliation
functionality.
type: string
required:
- status
- type
type: object
type: array
type: object
required:
- metadata
- spec
type: object
version: v1beta1
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: Cincinnati is the Schema for a Cincinnati service.
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
spec:
description: spec is the desired state of the Cincinnati service. The
operator will work to ensure that the desired configuration is applied
to the cluster.
properties:
graphDataImage:
description: graphDataImage is a container image that contains the
Cincinnati graph data.
type: string
registry:
description: registry is the container registry to use, such as "quay.io".
type: string
replicas:
description: replicas is the number of pods to run. When >=2, a PodDisruptionBudget
will ensure that voluntary disruption leaves at least one Pod running
at all times.
format: int32
minimum: 1
type: integer
repository:
description: repository is the repository to use in the Registry,
such as "openshift-release-dev/ocp-release"
type: string
required:
- graphDataImage
- registry
- replicas
- repository
type: object
status:
description: status contains information about the current state of the
Cincinnati service.
properties:
conditions:
description: Conditions describe the state of the Cincinnati resource.
items:
description: Condition represents the state of the operator's reconciliation
functionality.
properties:
lastHeartbeatTime:
format: date-time
type: string
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
description: ConditionType is the state of the operator's reconciliation
functionality.
type: string
required:
- status
- type
type: object
type: array
type: object
required:
- spec
type: object
served: true
storage: true
subresources:
status: {}
Empty file.
Empty file.
Empty file.
29 changes: 16 additions & 13 deletions functests/cincinnati_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ func setUp() {
}

func TestCustomResource(t *testing.T) {
ctx := context.Background()

k8sClient, err := getK8sClient()
if err != nil {
t.Fatal(err)
}

if err := waitForDeployment(k8sClient, operatorName); err != nil {
if err := waitForDeployment(ctx, k8sClient, operatorName); err != nil {
t.Fatal(err)
}

labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{"name": operatorName}}
listOptions := metav1.ListOptions{
LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
}
if pod, err := k8sClient.CoreV1().Pods(operatorNamespace).List(listOptions); err != nil {
if pod, err := k8sClient.CoreV1().Pods(operatorNamespace).List(ctx, listOptions); err != nil {
t.Fatal(err)
} else {
if len(pod.Items) < 1 {
Expand All @@ -63,17 +65,18 @@ func TestCustomResource(t *testing.T) {
}
}

if err := waitForService(k8sClient, operatorName+"-metrics"); err != nil {
if err := waitForService(ctx, k8sClient, operatorName+"-metrics"); err != nil {
t.Fatal(err)
}

defer func() {
if err := deleteCR(); err != nil {
ctx := context.Background()
if err := deleteCR(ctx); err != nil {
t.Log(err)
}
}()

if err := deployCR(); err != nil {
if err := deployCR(ctx); err != nil {
t.Fatal(err)
}

Expand All @@ -87,21 +90,21 @@ func TestCustomResource(t *testing.T) {
Resource(resource).
Namespace(operatorNamespace).
Name(customResourceName).
Do().
Do(ctx).
Into(result)
if err != nil {
t.Fatal(err)
}

if err := waitForDeployment(k8sClient, customResourceName); err != nil {
if err := waitForDeployment(ctx, k8sClient, customResourceName); err != nil {
t.Fatal(err)
}

labelSelector = metav1.LabelSelector{MatchLabels: map[string]string{"app": customResourceName}}
listOptions = metav1.ListOptions{
LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
}
if pod, err := k8sClient.CoreV1().Pods(operatorNamespace).List(listOptions); err != nil {
if pod, err := k8sClient.CoreV1().Pods(operatorNamespace).List(ctx, listOptions); err != nil {
t.Fatal(err)
} else {
if len(pod.Items) < 1 {
Expand All @@ -125,18 +128,18 @@ func TestCustomResource(t *testing.T) {
}
}

if err := waitForService(k8sClient, customResourceName+"-graph-builder"); err != nil {
if err := waitForService(ctx, k8sClient, customResourceName+"-graph-builder"); err != nil {
t.Fatal(err)
}

if err := waitForService(k8sClient, customResourceName+"-policy-engine"); err != nil {
if err := waitForService(ctx, k8sClient, customResourceName+"-policy-engine"); err != nil {
t.Fatal(err)
}

// Checks to see if a given PodDisruptionBudget is available after a specified amount of time.
// If the PodDisruptionBudget is not available after 30 * retries seconds, the condition function returns an error.
if err := wait.Poll(retryInterval, timeout, func() (done bool, err error) {
if _, err := k8sClient.PolicyV1beta1().PodDisruptionBudgets(operatorNamespace).Get(customResourceName, metav1.GetOptions{}); err != nil {
if _, err := k8sClient.PolicyV1beta1().PodDisruptionBudgets(operatorNamespace).Get(ctx, customResourceName, metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
t.Logf("Waiting for availability of %s PodDisruptionBudget\n", operatorName)
return false, nil
Expand All @@ -155,7 +158,7 @@ func TestCustomResource(t *testing.T) {
}

route := &routev1.Route{}
if err := crClient.Get(context.Background(), client.ObjectKey{
if err := crClient.Get(ctx, client.ObjectKey{
Namespace: operatorNamespace,
Name: routeName,
}, route); err != nil {
Expand All @@ -167,7 +170,7 @@ func TestCustomResource(t *testing.T) {
}
httpClient := &http.Client{Transport: tr}

req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/api/upgrades_info/v1/graph?channel=stable-4.4", route.Spec.Host), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s/api/upgrades_info/v1/graph?channel=stable-4.4", route.Spec.Host), nil)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading