-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Reason for Change**: - Add `feature-gates` flag to the Kaito controller. - Support the `karpenter` feature gate with default value, `false`. - Enable setting the feature gate flag via helm chart. In addition to some chores: - Exclude the auto generated and mock files from unit test coverage. - Upgrade k8s version using in the tests to the current supported version. **Requirements** - [x] added unit tests and e2e tests (if applicable). **Issue Fixed**: <!-- If this PR fixes GitHub issue 4321, add "Fixes #4321" to the next line. --> **Notes for Reviewers**: --------- Signed-off-by: Heba Elayoty <[email protected]>
- Loading branch information
Showing
13 changed files
with
153 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
package featuregates | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/azure/kaito/pkg/utils/consts" | ||
cliflag "k8s.io/component-base/cli/flag" | ||
) | ||
|
||
var ( | ||
// FeatureGates is a map that holds the feature gates and their default values for Kaito. | ||
FeatureGates = map[string]bool{ | ||
consts.FeatureFlagKarpenter: false, | ||
// Add more feature gates here | ||
} | ||
) | ||
|
||
// ParseAndValidateFeatureGates parses the feature gates flag and sets the environment variables for each feature. | ||
func ParseAndValidateFeatureGates(featureGates string) error { | ||
gateMap := map[string]bool{} | ||
if err := cliflag.NewMapStringBool(&gateMap).Set(featureGates); err != nil { | ||
return err | ||
} | ||
if len(gateMap) == 0 { | ||
// no feature gates set | ||
return nil | ||
} | ||
|
||
var invalidFeatures string | ||
for key, val := range gateMap { | ||
if _, ok := FeatureGates[key]; !ok { | ||
invalidFeatures = fmt.Sprintf("%s, %s", invalidFeatures, key) | ||
continue | ||
} | ||
FeatureGates[key] = val | ||
} | ||
|
||
if invalidFeatures != "" { | ||
return errors.New("invalid feature gate(s) " + invalidFeatures) | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
package featuregates | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func TestParseFeatureGates(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
featureGates string | ||
expectedError bool | ||
expectedValue string | ||
}{ | ||
{ | ||
name: "WithValidEnableFeatureGates", | ||
featureGates: "Karpenter=true", | ||
expectedError: false, | ||
expectedValue: "true", | ||
}, | ||
{ | ||
name: "WithDuplicateFeatureGates", | ||
featureGates: "Karpenter=false,Karpenter=true", | ||
expectedError: false, | ||
expectedValue: "true", // Apply the last value. | ||
}, | ||
{ | ||
name: "WithInvalidFeatureGates", | ||
featureGates: "invalid", | ||
expectedError: true, | ||
}, | ||
{ | ||
name: "WithUnsupportedFeatureGate", | ||
featureGates: "unsupported=true,Karpenter=false", | ||
expectedError: true, | ||
}, | ||
{ | ||
name: "WithValidDisableFeatureGates", | ||
featureGates: "Karpenter=false", | ||
expectedError: false, | ||
expectedValue: "false", | ||
}, | ||
{ | ||
name: "WithEmptyFeatureGates", | ||
featureGates: "", | ||
expectedError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := ParseAndValidateFeatureGates(tt.featureGates) | ||
if tt.expectedError { | ||
assert.Check(t, err != nil, "expected error but got nil") | ||
} else { | ||
assert.NilError(t, err) | ||
} | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
package consts | ||
|
||
const ( | ||
// WorkspaceFinalizer is used to make sure that workspace controller handles garbage collection. | ||
WorkspaceFinalizer = "workspace.finalizer.kaito.sh" | ||
DefaultReleaseNamespaceEnvVar = "RELEASE_NAMESPACE" | ||
FeatureFlagKarpenter = "Karpenter" | ||
) |