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

Add release version to status #1023

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -704,6 +704,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 @@ -257,10 +257,17 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
}

// finalize reconciliation
operatorReleaseVersion, err := cluster.SetRelease(r.Client)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would be useful to retrieve the version information before reconciling components? in case there are problems with certain components...

if err != nil {
r.Log.Error(err, "failed to get operator release version")
return ctrl.Result{}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we consider it as a critical error?

Copy link
Member Author

Choose a reason for hiding this comment

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

We probably need this to be critical error. It points to either error getting platform or CSV

}
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 = *operatorReleaseVersion
zdtsw marked this conversation as resolved.
Show resolved Hide resolved
})

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

Expand Down
6 changes: 6 additions & 0 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,15 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
}

// Finish reconciling
operatorReleaseVersion, err := cluster.SetRelease(r.Client)
if err != nil {
r.Log.Error(err, "failed to get operator release version")
return ctrl.Result{}, err
}
_, 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 = *operatorReleaseVersion
})
if err != nil {
r.Log.Error(err, "failed to update DSCInitialization status after successfully completed reconciliation")
Expand Down
29 changes: 29 additions & 0 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

"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 +121,31 @@ func GetPlatform(cli client.Client) (Platform, error) {
// check and return whether ODH or self-managed platform
return isSelfManaged(cli)
}

type Release struct {
Name Platform `json:"name,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
}

func SetRelease(cli client.Client) (*Release, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

May be it is GetRelease() since creates the structure and does not set it anywhere (and in sync with the error message).

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally do not see reason for pointer (*Release) here since you anyway dereference it right after the call and optimiser should avoid extra structure copying, but it's a matter of taste, probably.

initRelease := &Release{}
// Set platform
platform, err := GetPlatform(cli)
if err != nil {
return nil, err
}
initRelease.Name = platform

// Set Version
// Get watchNamespace
operatorNamespace, err := GetOperatorNamespace()
if err != nil {
return nil, err
}
csv, err := GetClusterServiceVersion(context.TODO(), cli, operatorNamespace)
if err != nil {
return nil, err
}
initRelease.Version = csv.Spec.Version
return initRelease, nil
}
Loading