forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447 from jiridanek/jd_merge_branch
RHOAIENG-15741: Sync v1.9-branch branch with main branch
- Loading branch information
Showing
10 changed files
with
252 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ controller-gen: ## Download controller-gen locally if necessary. | |
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
.PHONY: kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/v3/cmd/[email protected]) | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5@v5.0.2) | ||
|
||
ENVTEST = $(shell pwd)/bin/setup-envtest | ||
ENVTEST_VERSION?=v0.0.0-20240923090159-236e448db12c | ||
|
2 changes: 1 addition & 1 deletion
2
components/notebook-controller/config/overlays/openshift/params.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
odh-kf-notebook-controller-image=quay.io/opendatahub/kubeflow-notebook-controller:1.9-8369940 | ||
odh-kf-notebook-controller-image=quay.io/opendatahub/kubeflow-notebook-controller:main-3f931d2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,12 @@ IMG ?= quay.io/opendatahub/odh-notebook-controller | |
TAG ?= $(shell git describe --tags --always) | ||
|
||
KF_IMG ?= quay.io/opendatahub/kubeflow-notebook-controller | ||
KF_TAG ?= 1.9-8369940 | ||
KF_TAG ?= main-3f931d2 | ||
|
||
CONTAINER_ENGINE ?= podman | ||
|
||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.23 | ||
ENVTEST_K8S_VERSION = 1.26 | ||
|
||
# Kubernetes configuration | ||
K8S_NAMESPACE ?= odh-notebook-controller-system | ||
|
@@ -241,7 +241,7 @@ controller-gen: ## Download controller-gen locally if necessary. | |
KUSTOMIZE = $(LOCALBIN)/kustomize | ||
.PHONY: kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kustomize/v3/cmd/[email protected] | ||
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kustomize/kustomize/v5@v5.0.2 | ||
|
||
ENVTEST = $(LOCALBIN)/setup-envtest | ||
.PHONY: envtest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
odh-notebook-controller-image=quay.io/opendatahub/odh-notebook-controller:1.9-8369940 | ||
odh-notebook-controller-image=quay.io/opendatahub/odh-notebook-controller:main-3f931d2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
components/odh-notebook-controller/controllers/notebook_webhook_utils.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
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 controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/google/go-cmp/cmp" | ||
|
||
"github.com/go-logr/logr" | ||
) | ||
|
||
// UpdatesPending is either NoPendingUpdates, or a new value providing a Reason for the update. | ||
type UpdatesPending struct { | ||
Reason string | ||
} | ||
|
||
var ( | ||
NoPendingUpdates = &UpdatesPending{} | ||
) | ||
|
||
// FirstDifferenceReporter is a custom go-cmp reporter that only records the first difference. | ||
type FirstDifferenceReporter struct { | ||
path cmp.Path | ||
diff string | ||
} | ||
|
||
func (r *FirstDifferenceReporter) PushStep(ps cmp.PathStep) { | ||
r.path = append(r.path, ps) | ||
} | ||
|
||
func (r *FirstDifferenceReporter) Report(rs cmp.Result) { | ||
if r.diff == "" && !rs.Equal() { | ||
vx, vy := r.path.Last().Values() | ||
r.diff = fmt.Sprintf("%#v: %+v != %+v", r.path, vx, vy) | ||
} | ||
} | ||
|
||
func (r *FirstDifferenceReporter) PopStep() { | ||
r.path = r.path[:len(r.path)-1] | ||
} | ||
|
||
func (r *FirstDifferenceReporter) String() string { | ||
return r.diff | ||
} | ||
|
||
// getStructDiff compares a and b, reporting the first difference it found in a human-readable single-line string. | ||
func getStructDiff(ctx context.Context, a any, b any) (result string) { | ||
log := logr.FromContextOrDiscard(ctx) | ||
|
||
// calling cmp.Equal may panic, get ready for it | ||
result = "failed to compute the reason for why there is a pending restart" | ||
defer func() { | ||
if r := recover(); r != nil { | ||
log.Error(fmt.Errorf("failed to compute struct difference: %+v", r), "Cannot determine reason for restart") | ||
} | ||
}() | ||
|
||
var comparator FirstDifferenceReporter | ||
eq := cmp.Equal(a, b, cmp.Reporter(&comparator)) | ||
if eq { | ||
log.Error(nil, "Unexpectedly attempted to diff structs that are actually equal") | ||
} | ||
result = comparator.String() | ||
|
||
return | ||
} |
64 changes: 64 additions & 0 deletions
64
components/odh-notebook-controller/controllers/notebook_webhook_utils_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
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 controllers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFirstDifferenceReporter(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
a any | ||
b any | ||
diff string | ||
}{ | ||
{"", 42, 42, ""}, | ||
{"", v1.Pod{Spec: v1.PodSpec{NodeName: "node1"}}, v1.Pod{Spec: v1.PodSpec{NodeName: "node2"}}, "{v1.Pod}.Spec.NodeName: node1 != node2"}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var reporter FirstDifferenceReporter | ||
eq := cmp.Equal(tt.a, tt.b, cmp.Reporter(&reporter)) | ||
assert.Equal(t, tt.diff == "", eq) | ||
assert.Equal(t, tt.diff, reporter.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetStructDiff(t *testing.T) { | ||
var tests = []struct { | ||
name string | ||
a any | ||
b any | ||
expected string | ||
}{ | ||
{"simple numbers", 42, 42, ""}, | ||
{"differing pods", v1.Pod{Spec: v1.PodSpec{NodeName: "node1"}}, v1.Pod{Spec: v1.PodSpec{NodeName: "node2"}}, "{v1.Pod}.Spec.NodeName: node1 != node2"}, | ||
} | ||
|
||
for _, v := range tests { | ||
t.Run(v.name, func(t *testing.T) { | ||
diff := getStructDiff(context.Background(), v.a, v.b) | ||
assert.Equal(t, diff, v.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters