Skip to content

Commit

Permalink
Add release version to status (opendatahub-io#1023)
Browse files Browse the repository at this point in the history
* Add release version to status

* Set Release version

* Address comments and update manifests

* Update api docs

* Fix unit tests

* fix linters
  • Loading branch information
VaishnaviHire authored May 30, 2024
1 parent d90983b commit 34283e7
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apis/datasciencecluster/v1/datasciencecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"errors"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"reflect"

conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
Expand Down Expand Up @@ -103,6 +104,9 @@ type DataScienceClusterStatus struct {

// List of components with status if installed or not
InstalledComponents map[string]bool `json:"installedComponents,omitempty"`

// Version and release type
Release cluster.Release `json:"release,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
1 change: 1 addition & 0 deletions apis/datasciencecluster/v1/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions apis/dscinitialization/v1/dscinitialization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
operatorv1 "github.com/openshift/api/operator/v1"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -110,6 +111,9 @@ type DSCInitializationStatus struct {
// +optional
RelatedObjects []corev1.ObjectReference `json:"relatedObjects,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`

// Version and release type
Release cluster.Release `json:"release,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
1 change: 1 addition & 0 deletions apis/dscinitialization/v1/zz_generated.deepcopy.go

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 @@ -703,6 +703,14 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
release:
description: Version and release type
properties:
name:
type: string
version:
type: string
type: object
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
release:
description: Version and release type
properties:
name:
type: string
version:
type: string
type: object
type: object
type: object
served: true
Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ annotations:
operators.operatorframework.io.bundle.package.v1: opendatahub-operator
operators.operatorframework.io.bundle.channels.v1: fast
operators.operatorframework.io.bundle.channel.default.v1: fast
operators.operatorframework.io.metrics.builder: operator-sdk-v1.24.1
operators.operatorframework.io.metrics.builder: operator-sdk-v1.31.0
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,14 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
release:
description: Version and release type
properties:
name:
type: string
version:
type: string
type: object
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
release:
description: Version and release type
properties:
name:
type: string
version:
type: string
type: object
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ const (
func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:maintidx,gocyclo
r.Log.Info("Reconciling DataScienceCluster resources", "Request.Name", req.Name)

// Get information on version
currentOperatorReleaseVersion, err := cluster.GetRelease(r.Client)
if err != nil {
r.Log.Error(err, "failed to get operator release version")
return ctrl.Result{}, err
}

instances := &dsc.DataScienceClusterList{}

if err := r.Client.List(ctx, instances); err != nil {
Expand Down Expand Up @@ -260,7 +267,9 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
instance, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dsc.DataScienceCluster) {
status.SetCompleteCondition(&saved.Status.Conditions, status.ReconcileCompleted, "DataScienceCluster resource reconciled successfully")
saved.Status.Phase = status.PhaseReady
saved.Status.Release = currentOperatorReleaseVersion
})

if err != nil {
r.Log.Error(err, "failed to update DataScienceCluster conditions after successfully completed reconciliation")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ type DSCInitializationReconciler struct { //nolint:golint,revive // Readability
func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:funlen,gocyclo,maintidx
r.Log.Info("Reconciling DSCInitialization.", "DSCInitialization Request.Name", req.Name)

currentOperatorReleaseVersion, err := cluster.GetRelease(r.Client)
if err != nil {
r.Log.Error(err, "failed to get operator release version")
return ctrl.Result{}, err
}

instances := &dsciv1.DSCInitializationList{}
if err := r.Client.List(ctx, instances); err != nil {
r.Log.Error(err, "Failed to retrieve DSCInitialization resource.", "DSCInitialization Request.Name", req.Name)
Expand Down Expand Up @@ -118,7 +124,6 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
return ctrl.Result{}, nil
}

var err error
// Start reconciling
if instance.Status.Conditions == nil {
reason := status.ReconcileInit
Expand Down Expand Up @@ -268,6 +273,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
_, err = status.UpdateWithRetry[*dsciv1.DSCInitialization](ctx, r.Client, instance, func(saved *dsciv1.DSCInitialization) {
status.SetCompleteCondition(&saved.Status.Conditions, status.ReconcileCompleted, status.ReconcileCompletedMessage)
saved.Status.Phase = status.PhaseReady
saved.Status.Release = currentOperatorReleaseVersion
})
if err != nil {
r.Log.Error(err, "failed to update DSCInitialization status after successfully completed reconciliation")
Expand Down
2 changes: 2 additions & 0 deletions docs/api-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ _Appears in:_
| `relatedObjects` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#objectreference-v1-core) array_ | RelatedObjects is a list of objects created and maintained by this operator.<br />Object references will be added to this list after they have been created AND found in the cluster. | | |
| `errorMessage` _string_ | | | |
| `installedComponents` _object (keys:string, values:boolean)_ | List of components with status if installed or not | | |
| `release` _[Release](#release)_ | Version and release type | | |


#### IngressGatewaySpec
Expand Down Expand Up @@ -627,6 +628,7 @@ _Appears in:_
| `conditions` _Condition array_ | Conditions describes the state of the DSCInitializationStatus resource | | |
| `relatedObjects` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#objectreference-v1-core) array_ | RelatedObjects is a list of objects created and maintained by this operator.<br />Object references will be added to this list after they have been created AND found in the cluster | | |
| `errorMessage` _string_ | | | |
| `release` _[Release](#release)_ | Version and release type | | |


#### DevFlags
Expand Down
39 changes: 39 additions & 0 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"strings"

"github.com/blang/semver/v4"
"github.com/operator-framework/api/pkg/lib/version"
ofapi "github.com/operator-framework/api/pkg/operators/v1alpha1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -120,3 +122,40 @@ func GetPlatform(cli client.Client) (Platform, error) {
// check and return whether ODH or self-managed platform
return isSelfManaged(cli)
}

// Release includes information on operator version and platform
// +kubebuilder:object:generate=true
type Release struct {
Name Platform `json:"name,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
}

func GetRelease(cli client.Client) (Release, error) {
initRelease := Release{}
// Set platform
platform, err := GetPlatform(cli)
if err != nil {
return initRelease, err
}
initRelease.Name = platform

// For unit-tests
if os.Getenv("CI") == "true" {
initRelease.Version = version.OperatorVersion{
Version: semver.Version{},
}
return initRelease, nil
}
// Set Version
// Get watchNamespace
operatorNamespace, err := GetOperatorNamespace()
if err != nil {
return initRelease, err
}
csv, err := GetClusterServiceVersion(context.TODO(), cli, operatorNamespace)
if err != nil {
return initRelease, err
}
initRelease.Version = csv.Spec.Version
return initRelease, nil
}
40 changes: 40 additions & 0 deletions pkg/cluster/zz_generated.deepcopy.go

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

0 comments on commit 34283e7

Please sign in to comment.