-
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.
Merge branch 'main' into helayoty/security-fixes
- Loading branch information
Showing
14 changed files
with
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
apiVersion: karpenter.sh/v1beta1 | ||
kind: NodePool | ||
metadata: | ||
name: kaito-nodepool | ||
annotations: | ||
kubernetes.io/description: "General purpose NodePool for generic workloads" | ||
spec: | ||
disruption: | ||
consolidateAfter: Never | ||
consolidationPolicy: WhenEmpty | ||
expireAfter: Never | ||
template: | ||
spec: | ||
requirements: | ||
--- | ||
apiVersion: karpenter.azure.com/v1alpha2 | ||
kind: AKSNodeClass | ||
metadata: | ||
name: default | ||
spec: | ||
imageFamily: Ubuntu2204 |
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" | ||
) |