-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add importer's requests and limits for virtualization conf…
…ig (#266) Signed-off-by: Isteb4k <[email protected]>
- Loading branch information
Showing
26 changed files
with
333 additions
and
101 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
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
72 changes: 72 additions & 0 deletions
72
images/virtualization-artifact/pkg/config/load_import_settings.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,72 @@ | ||
/* | ||
Copyright 2024 Flant JSC | ||
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 config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/deckhouse/virtualization-controller/pkg/common" | ||
) | ||
|
||
type ImportSettings struct { | ||
ImporterImage string | ||
UploaderImage string | ||
Requirements corev1.ResourceRequirements | ||
} | ||
|
||
func LoadImportSettingsFromEnv() (ImportSettings, error) { | ||
var settings ImportSettings | ||
var err error | ||
settings.ImporterImage, err = GetRequiredEnvVar(common.ImporterPodImageNameVar) | ||
if err != nil { | ||
return ImportSettings{}, err | ||
} | ||
|
||
settings.UploaderImage, err = GetRequiredEnvVar(common.UploaderPodImageNameVar) | ||
if err != nil { | ||
return ImportSettings{}, err | ||
} | ||
|
||
limits := os.Getenv(common.ImporterLimitsVar) | ||
if limits != "" { | ||
err = json.Unmarshal([]byte(limits), &settings.Requirements.Limits) | ||
if err != nil { | ||
return ImportSettings{}, err | ||
} | ||
} | ||
requests := os.Getenv(common.ImporterRequestsVar) | ||
if requests != "" { | ||
err = json.Unmarshal([]byte(requests), &settings.Requirements.Requests) | ||
if err != nil { | ||
return ImportSettings{}, err | ||
} | ||
} | ||
|
||
return settings, nil | ||
} | ||
|
||
func GetRequiredEnvVar(name string) (string, error) { | ||
val := os.Getenv(name) | ||
if val == "" { | ||
return "", fmt.Errorf("environment variable %q undefined", name) | ||
} | ||
return val, nil | ||
} |
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
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
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
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
Oops, something went wrong.