Skip to content

Commit

Permalink
Merge pull request red-hat-data-services#245 from VedantMahabaleshwar…
Browse files Browse the repository at this point in the history
…kar/eng-10286

add sanity check on regex match results while determining runtime image
  • Loading branch information
openshift-merge-bot[bot] authored and VedantMahabaleshwarkar committed Jul 30, 2024
1 parent aa2d741 commit db160a6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" POD_NAMESPACE=default go test -v ./controllers/... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" POD_NAMESPACE=default go test ./controllers/... -coverprofile cover.out

.PHONY: e2e-test
e2e-test: manifests generate fmt vet ## Run e2e-tests.
Expand Down
29 changes: 29 additions & 0 deletions controllers/comparators/configmap_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
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 comparators

import (
"reflect"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetConfigMapComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedConfigMap := deployed.(*corev1.ConfigMap)
requestedConfigMap := requested.(*corev1.ConfigMap)
return reflect.DeepEqual(deployedConfigMap.Data, requestedConfigMap.Data) &&
reflect.DeepEqual(deployedConfigMap.Labels, requestedConfigMap.Labels)
}
}
1 change: 1 addition & 0 deletions controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
TgisImageName = "text-generation-inference"
VllmImageName = "vllm"
CaikitImageName = "caikit-nlp"
ServingRuntimeFallBackImageName = "unsupported"
)

// openshift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (r *KserveMetricsDashboardReconciler) Reconcile(ctx context.Context, log lo
func (r *KserveMetricsDashboardReconciler) createDesiredResource(ctx context.Context, log logr.Logger, isvc *kservev1beta1.InferenceService) (*corev1.ConfigMap, error) {

var err error
var servingRuntime string
runtime := &kservev1alpha1.ServingRuntime{}
supported := false
// resolve SR
Expand Down Expand Up @@ -125,7 +126,12 @@ func (r *KserveMetricsDashboardReconciler) createDesiredResource(ctx context.Con
servingRuntimeImage := runtime.Spec.Containers[0].Image
re := regexp.MustCompile(`/([^/@]+)[@:]`)
findImageName := re.FindStringSubmatch(servingRuntimeImage)
servingRuntime := findImageName[1]
// sanity check for regex match, will fall back to a known string that will lead to a configmap for unsupported metrics
if len(findImageName) < 2 {
servingRuntime = constants.ServingRuntimeFallBackImageName
} else {
servingRuntime = findImageName[1]
}

runtimeMetricsData := map[string]string{
constants.OvmsImageName: constants.OvmsMetricsData,
Expand Down
50 changes: 50 additions & 0 deletions controllers/resources/configmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
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 resources

import (
"context"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type ConfigMapHandler interface {
FetchConfigMap(ctx context.Context, log logr.Logger, key types.NamespacedName) (*corev1.ConfigMap, error)
}

type configMapHandler struct {
client client.Client
}

func NewConfigMapHandler(client client.Client) ConfigMapHandler {
return &configMapHandler{
client: client,
}
}

func (r *configMapHandler) FetchConfigMap(ctx context.Context, log logr.Logger, key types.NamespacedName) (*corev1.ConfigMap, error) {
configMap := &corev1.ConfigMap{}
err := r.client.Get(ctx, key, configMap)
if err != nil && errors.IsNotFound(err) {
log.V(1).Info("ConfigMap not found.")
return nil, nil
} else if err != nil {
return nil, err
}
log.V(1).Info("Successfully fetched ConfigMap", "ConfigMap:", key.Name)
return configMap, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- '--model_name={{.Name}}'
- '--model_dir=/mnt/models'
- '--http_port=8080'
image: 'kserve/unsupportedimage:v0.12.1'
image: 'kserve/dummy-sklearn-server' #This image does not exist.
name: kserve-container
resources:
limits:
Expand Down

0 comments on commit db160a6

Please sign in to comment.