-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test to verify cni-metrics-helper puts metrics to CW (#1461)
* add test to verify cni-metrics-helper puts metrics to CW * add helm chart for cni-metric-helper
- Loading branch information
Showing
19 changed files
with
974 additions
and
83 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 controller | ||
|
||
const ( | ||
CNIMetricsHelperChartDir = "/test/helm/charts/cni-metrics-helper" | ||
CNIMetricsHelperReleaseName = "cni-metrics-helper" | ||
CNIMetricHelperNamespace = "kube-system" | ||
) |
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,56 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 controller | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/aws/amazon-vpc-cni-k8s/test/framework/helm" | ||
) | ||
|
||
type InstallationManager interface { | ||
InstallCNIMetricsHelper(image string, tag string) error | ||
UnInstallCNIMetricsHelper() error | ||
} | ||
|
||
func NewDefaultInstallationManager(manager helm.ReleaseManager) InstallationManager { | ||
return &defaultInstallationManager{releaseManager: manager} | ||
} | ||
|
||
type defaultInstallationManager struct { | ||
releaseManager helm.ReleaseManager | ||
} | ||
|
||
func (d *defaultInstallationManager) InstallCNIMetricsHelper(image string, tag string) error { | ||
dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) | ||
projectRoot := strings.SplitAfter(dir, "amazon-vpc-cni-k8s")[0] | ||
|
||
values := map[string]interface{}{ | ||
"image": map[string]interface{}{ | ||
"repository": image, | ||
"tag": tag, | ||
}, | ||
} | ||
|
||
_, err := d.releaseManager.InstallUnPackagedRelease(projectRoot+CNIMetricsHelperChartDir, | ||
CNIMetricsHelperReleaseName, CNIMetricHelperNamespace, values) | ||
return err | ||
} | ||
|
||
func (d *defaultInstallationManager) UnInstallCNIMetricsHelper() error { | ||
_, err := d.releaseManager.UninstallRelease(CNIMetricHelperNamespace, CNIMetricsHelperReleaseName) | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 helm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/prometheus/common/log" | ||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/chart/loader" | ||
"helm.sh/helm/v3/pkg/cli" | ||
"helm.sh/helm/v3/pkg/release" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
) | ||
|
||
type ReleaseManager interface { | ||
InstallUnPackagedRelease(chart string, releaseName string, namespace string, | ||
values map[string]interface{}) (*release.Release, error) | ||
UninstallRelease(namespace string, releaseName string) (*release.UninstallReleaseResponse, error) | ||
} | ||
|
||
type defaultReleaseManager struct { | ||
kubeConfig string | ||
} | ||
|
||
func NewDefaultReleaseManager(kubeConfig string) ReleaseManager { | ||
return &defaultReleaseManager{kubeConfig: kubeConfig} | ||
} | ||
|
||
func (d *defaultReleaseManager) InstallUnPackagedRelease(chart string, releaseName string, namespace string, | ||
values map[string]interface{}) (*release.Release, error) { | ||
actionConfig := d.obtainActionConfig(namespace) | ||
|
||
installAction := action.NewInstall(actionConfig) | ||
installAction.Namespace = namespace | ||
installAction.Wait = true | ||
installAction.ReleaseName = releaseName | ||
|
||
cp, err := installAction.ChartPathOptions.LocateChart(chart, cli.New()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
chartRequested, err := loader.Load(cp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return installAction.Run(chartRequested, values) | ||
} | ||
|
||
func (d *defaultReleaseManager) UninstallRelease(namespace string, releaseName string) (*release.UninstallReleaseResponse, error) { | ||
actionConfig := d.obtainActionConfig(namespace) | ||
|
||
uninstallAction := action.NewUninstall(actionConfig) | ||
return uninstallAction.Run(releaseName) | ||
} | ||
|
||
func (d *defaultReleaseManager) obtainActionConfig(namespace string) *action.Configuration { | ||
cfgFlag := genericclioptions.NewConfigFlags(false) | ||
cfgFlag.KubeConfig = &d.kubeConfig | ||
cfgFlag.Namespace = &namespace | ||
actionConfig := new(action.Configuration) | ||
actionConfig.Init(cfgFlag, namespace, "secrets", func(format string, v ...interface{}) { | ||
message := fmt.Sprintf(format, v...) | ||
log.Info(message) | ||
}) | ||
return actionConfig | ||
} |
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,38 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 services | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/cloudwatch" | ||
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface" | ||
) | ||
|
||
type CloudWatch interface { | ||
GetMetricStatistics(getMetricStatisticsInput *cloudwatch.GetMetricStatisticsInput) (*cloudwatch.GetMetricStatisticsOutput, error) | ||
} | ||
|
||
type defaultCloudWatch struct { | ||
cloudwatchiface.CloudWatchAPI | ||
} | ||
|
||
func NewCloudWatch(session *session.Session) CloudWatch { | ||
return &defaultCloudWatch{ | ||
CloudWatchAPI: cloudwatch.New(session), | ||
} | ||
} | ||
|
||
func (d *defaultCloudWatch) GetMetricStatistics(getMetricStatisticsInput *cloudwatch.GetMetricStatisticsInput) (*cloudwatch.GetMetricStatisticsOutput, error) { | ||
return d.CloudWatchAPI.GetMetricStatistics(getMetricStatisticsInput) | ||
} |
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.