Repository navigation
Expand file tree
/
Copy pathmodelsasservice.go
More file actions
132 lines (109 loc) · 4.61 KB
/
Copy pathmodelsasservice.go
File metadata and controls
132 lines (109 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright 2025.
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 modelsasservice
import (
"context"
"errors"
"fmt"
operatorv1 "github.com/openshift/api/operator/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/opendatahub-io/opendatahub-operator/v2/api/common"
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/api/components/v1alpha1"
dscv2 "github.com/opendatahub-io/opendatahub-operator/v2/api/datasciencecluster/v2"
cr "github.com/opendatahub-io/opendatahub-operator/v2/internal/controller/components/registry"
"github.com/opendatahub-io/opendatahub-operator/v2/internal/controller/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/conditions"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
type componentHandler struct{}
func init() { //nolint:gochecknoinits
cr.Add(&componentHandler{})
}
// GetName returns the component name for ModelsAsService.
func (s *componentHandler) GetName() string {
return componentApi.ModelsAsServiceComponentName
}
// Init initializes the ModelsAsService component.
func (s *componentHandler) Init(_ common.Platform) error {
mi := baseManifestInfo(BaseManifestsSourcePath)
if err := odhdeploy.ApplyParams(mi.String(), "params.env", imagesMap, extraParamsMap); err != nil {
return fmt.Errorf("failed to update params on path %s: %w", mi, err)
}
return nil
}
// NewCRObject constructs a new ModelsAsService Custom Resource.
func (s *componentHandler) NewCRObject(dsc *dscv2.DataScienceCluster) common.PlatformObject {
// TODO: ModelsAsService should be integrated into the KServe component
// For now, we create a basic ModelsAsService CR with default values
return &componentApi.ModelsAsService{
TypeMeta: metav1.TypeMeta{
Kind: componentApi.ModelsAsServiceKind,
APIVersion: componentApi.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: componentApi.ModelsAsServiceInstanceName,
Annotations: map[string]string{
annotations.ManagementStateAnnotation: string(operatorv1.Managed),
},
},
Spec: componentApi.ModelsAsServiceSpec{
Gateway: componentApi.GatewaySpec{
Namespace: DefaultGatewayNamespace,
Name: DefaultGatewayName,
},
},
}
}
// IsEnabled checks if the ModelsAsService component should be deployed.
func (s *componentHandler) IsEnabled(dsc *dscv2.DataScienceCluster) bool {
// For now, return false.
// This logic will need to be updated once DSCModelsAsService is integrated into the KServe spec
return false
}
// UpdateDSCStatus updates the ModelsAsService component status in the DataScienceCluster.
func (s *componentHandler) UpdateDSCStatus(ctx context.Context, rr *types.ReconciliationRequest) (metav1.ConditionStatus, error) {
cs := metav1.ConditionUnknown
c := componentApi.ModelsAsService{}
c.Name = componentApi.ModelsAsServiceInstanceName
if err := rr.Client.Get(ctx, client.ObjectKeyFromObject(&c), &c); err != nil && !k8serr.IsNotFound(err) {
return cs, nil
}
dsc, ok := rr.Instance.(*dscv2.DataScienceCluster)
if !ok {
return cs, errors.New("failed to convert to DataScienceCluster")
}
// Since s.IsEnabled() always returns false, for now, the following code will always mark the ready condition as not ready.
// This will need to be updated once DSCModelsAsService is properly integrated
// Set the ready condition based on the ModelsAsService status
rr.Conditions.MarkFalse(ReadyConditionType)
if s.IsEnabled(dsc) {
if rc := conditions.FindStatusCondition(c.GetStatus(), status.ConditionTypeReady); rc != nil {
rr.Conditions.MarkFrom(ReadyConditionType, *rc)
cs = rc.Status
} else {
cs = metav1.ConditionFalse
}
} else {
rr.Conditions.MarkFalse(
ReadyConditionType,
conditions.WithReason(string(operatorv1.Removed)),
conditions.WithMessage("Component ManagementState is set to %s", string(operatorv1.Removed)),
conditions.WithSeverity(common.ConditionSeverityInfo),
)
}
return cs, nil
}