Skip to content

Commit

Permalink
fix: Move validatePythonVersion after checking image existance (#508)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. Run unit tests and ensure that they are passing
2. If your change introduces any API changes, make sure to update the
e2e tests
3. Make sure documentation is updated for your PR!

-->

**What this PR does / why we need it**:
<!-- Explain here the context and why you're making the change. What is
the problem you're trying to solve. --->

For existing models that were previously successfully built using Python
3.7.* won't be able to be deployed anymore since the new
validatePythonVersion() introduced in #500 will invalidate it.

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

Fixes failed redeployment or re-execution of existing models with Python
3.7.*

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required. Enter your extended release note in
the block below.
If the PR requires additional action from users switching to the new
release, include the string "action required".

For more information about release notes, see kubernetes' guide here:
http://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note
NONE
```

**Checklist**

- [ ] Added unit test, integration, and/or e2e tests
- [x] Tested locally
- [ ] Updated documentation
- [ ] Update Swagger spec if the PR introduce API changes
- [ ] Regenerated Golang and Python client if the PR introduce API
changes
  • Loading branch information
ariefrahmansyah authored Dec 15, 2023
1 parent e8f5ebb commit f168838
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 45 deletions.
8 changes: 4 additions & 4 deletions api/pkg/imagebuilder/imagebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ func (c *imageBuilder) validatePythonVersion(version *models.Version) error {

// GetMainAppPath Returns the path to run the main.py of batch predictor, as configured via env var
func (c *imageBuilder) GetMainAppPath(version *models.Version) (string, error) {
if err := c.validatePythonVersion(version); err != nil {
return "", err
}

baseImageTag := c.config.BaseImage
if baseImageTag.MainAppPath == "" {
return "", fmt.Errorf("mainAppPath is not set for tag %s", version.PythonVersion)
Expand Down Expand Up @@ -202,6 +198,10 @@ func (c *imageBuilder) BuildImage(ctx context.Context, project mlp.Project, mode
return imageRef, nil
}

if err := c.validatePythonVersion(version); err != nil {
return "", err
}

startTime := time.Now()
result := "failed"

Expand Down
89 changes: 48 additions & 41 deletions api/pkg/imagebuilder/imagebuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ var (
"--use-new-run",
}

defaultSupportedPythonVersions = []string{"3.8.*", "3.9.*", "3.10.*"}

config = Config{
BuildNamespace: testBuildNamespace,
BaseImage: cfg.BaseImageConfig{
Expand All @@ -118,13 +120,14 @@ var (
BuildContextSubPath: "python/pyfunc-server",
DockerfilePath: "./Dockerfile",
},
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
SupportedPythonVersions: defaultSupportedPythonVersions,
DefaultResources: cfg.ResourceRequestsLimits{
Requests: cfg.Resource{
CPU: "500m",
Expand Down Expand Up @@ -156,13 +159,14 @@ var (
BuildContextSubPath: "python/pyfunc-server",
DockerfilePath: "./Dockerfile",
},
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
SupportedPythonVersions: defaultSupportedPythonVersions,
DefaultResources: cfg.ResourceRequestsLimits{
Requests: cfg.Resource{
CPU: "500m",
Expand Down Expand Up @@ -555,14 +559,15 @@ func TestBuildImage(t *testing.T) {
BuildContextSubPath: "python/pyfunc-server",
DockerfilePath: "./Dockerfile",
},
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
DefaultResources: config.DefaultResources,
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
SupportedPythonVersions: defaultSupportedPythonVersions,
DefaultResources: config.DefaultResources,
NodeSelectors: map[string]string{
"cloud.google.com/gke-nodepool": "image-building-job-node-pool",
},
Expand Down Expand Up @@ -685,14 +690,15 @@ func TestBuildImage(t *testing.T) {
BuildContextSubPath: "python/pyfunc-server",
DockerfilePath: "./Dockerfile",
},
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
DefaultResources: config.DefaultResources,
DockerRegistry: testDockerRegistry,
BuildTimeoutDuration: timeout,
ClusterName: "my-cluster",
GcpProject: "test-project",
Environment: testEnvironmentName,
KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0",
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
SupportedPythonVersions: defaultSupportedPythonVersions,
DefaultResources: config.DefaultResources,
Tolerations: []v1.Toleration{
{
Key: "image-build-job",
Expand Down Expand Up @@ -821,17 +827,18 @@ func TestBuildImage(t *testing.T) {
BuildContextURI: testBuildContextURL,
DockerfilePath: "./Dockerfile",
},
DockerRegistry: config.DockerRegistry,
BuildTimeoutDuration: config.BuildTimeoutDuration,
ClusterName: config.ClusterName,
GcpProject: config.GcpProject,
Environment: config.Environment,
KanikoImage: config.KanikoImage,
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
DefaultResources: config.DefaultResources,
MaximumRetry: config.MaximumRetry,
NodeSelectors: config.NodeSelectors,
Tolerations: config.Tolerations,
DockerRegistry: config.DockerRegistry,
BuildTimeoutDuration: config.BuildTimeoutDuration,
ClusterName: config.ClusterName,
GcpProject: config.GcpProject,
Environment: config.Environment,
KanikoImage: config.KanikoImage,
KanikoAdditionalArgs: defaultKanikoAdditionalArgs,
SupportedPythonVersions: defaultSupportedPythonVersions,
DefaultResources: config.DefaultResources,
MaximumRetry: config.MaximumRetry,
NodeSelectors: config.NodeSelectors,
Tolerations: config.Tolerations,
},
},
{
Expand Down

0 comments on commit f168838

Please sign in to comment.