-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds scorecard bundle metadata "mediaType" and "config",
which are written to bundle metadata on `generate bundle` when either `--overwrite` is set or metadata files do not exist. "config.yaml" is a hard-coded file name for the scorecard config file. cmd/operator-sdk/generate/bundle: write scorecard bundle metadata to annotations.yaml and bundle.Dockerfile cmd/operator-sdk/scorecard: use scorecard metadata config path if it exists, defaulting to `tests/scorecard/config.yaml` internal/annotations: consolidate annotations for metrics and scorecard in subpackages here internal/scorecard: encode "config.yaml" as hard-coded file name for the scorecard config, and add metadata to example annotations.yaml files
- Loading branch information
Showing
18 changed files
with
311 additions
and
214 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,6 @@ | ||
entries: | ||
- description: > | ||
`generate bundle` now adds scorecard bundle metadata to bundle.Dockerfile and annotations.yaml | ||
if `--overwrite` is set (the default in a project's `Makefile`) or both files do not exist. | ||
kind: addition | ||
breaking: false |
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,96 @@ | ||
// Copyright 2020 The Operator-SDK Authors | ||
// | ||
// 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 metrics | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"sigs.k8s.io/kubebuilder/pkg/model/config" | ||
|
||
sdkversion "github.com/operator-framework/operator-sdk/version" | ||
) | ||
|
||
// Static bundle annotation values. | ||
const ( | ||
mediaTypeV1 = "metrics+v1" | ||
) | ||
|
||
// Bundle annotation keys. | ||
const ( | ||
mediaTypeBundleAnnotation = "operators.operatorframework.io.metrics.mediatype.v1" | ||
builderBundleAnnotation = "operators.operatorframework.io.metrics.builder" | ||
layoutBundleAnnotation = "operators.operatorframework.io.metrics.project_layout" | ||
) | ||
|
||
// Object annotation keys. | ||
const ( | ||
BuilderObjectAnnotation = "operators.operatorframework.io/builder" | ||
LayoutObjectAnnotation = "operators.operatorframework.io/project_layout" | ||
) | ||
|
||
// MakeBundleMetadataLabels returns the SDK metric labels which will be added | ||
// to bundle resources like bundle.Dockerfile and annotations.yaml. | ||
func MakeBundleMetadataLabels(cfg *config.Config) map[string]string { | ||
return map[string]string{ | ||
mediaTypeBundleAnnotation: mediaTypeV1, | ||
builderBundleAnnotation: getSDKBuilder(sdkversion.Version), | ||
layoutBundleAnnotation: getSDKProjectLayout(cfg), | ||
} | ||
} | ||
|
||
// MakeObjectAnnotations returns the SDK metric annotations which will be added | ||
// to CustomResourceDefinitions and ClusterServiceVersions. | ||
func MakeBundleObjectAnnotations(cfg *config.Config) map[string]string { | ||
return map[string]string{ | ||
BuilderObjectAnnotation: getSDKBuilder(sdkversion.Version), | ||
LayoutObjectAnnotation: getSDKProjectLayout(cfg), | ||
} | ||
} | ||
|
||
func getSDKBuilder(rawSDKVersion string) string { | ||
return "operator-sdk" + "-" + parseVersion(rawSDKVersion) | ||
} | ||
|
||
func parseVersion(input string) string { | ||
re := regexp.MustCompile(`v[0-9]+\.[0-9]+\.[0-9]+`) | ||
version := re.FindString(input) | ||
if version == "" { | ||
return "unknown" | ||
} | ||
|
||
if isUnreleased(input) { | ||
version = version + "+git" | ||
} | ||
return version | ||
} | ||
|
||
// isUnreleased returns true if sdk was not built from released version. | ||
func isUnreleased(input string) bool { | ||
if strings.Contains(input, "+git") { | ||
return true | ||
} | ||
re := regexp.MustCompile(`v[0-9]+\.[0-9]+\.[0-9]+-.+`) | ||
return re.MatchString(input) | ||
} | ||
|
||
// getSDKProjectLayout returns the `layout` field in PROJECT file that is v3. | ||
// If not, it will return "go" because that was the only project type supported for project versions < v3. | ||
func getSDKProjectLayout(cfg *config.Config) string { | ||
if !cfg.IsV3() || cfg.Layout == "" { | ||
return "go" | ||
} | ||
return cfg.Layout | ||
} |
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,54 @@ | ||
// Copyright 2020 The Operator-SDK Authors | ||
// | ||
// 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 scorecard | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
// Static bundle annotation values. | ||
const ( | ||
mediaTypeV1 = "scorecard+v1" | ||
) | ||
|
||
// Bundle annotation keys. | ||
// NB(estroz): version these keys based on their "vX" version (either with the version in their names, | ||
// or in subpackages). This may be a requirement if we create "v2" keys. | ||
const ( | ||
mediaTypeBundleKey = "operators.operatorframework.io.test.mediatype.v1" | ||
configBundleKey = "operators.operatorframework.io.test.config.v1" | ||
) | ||
|
||
func MakeBundleMetadataLabels(configDir string) map[string]string { | ||
return map[string]string{ | ||
mediaTypeBundleKey: mediaTypeV1, | ||
configBundleKey: configDir, | ||
} | ||
} | ||
|
||
func GetConfigDir(labels map[string]string) (value string, hasKey bool) { | ||
if configKey, hasMTKey := configKeyForMediaType(labels); hasMTKey { | ||
value, hasKey = labels[configKey] | ||
} | ||
return filepath.Clean(filepath.FromSlash(value)), hasKey | ||
} | ||
|
||
func configKeyForMediaType(labels map[string]string) (string, bool) { | ||
switch labels[mediaTypeBundleKey] { | ||
case mediaTypeV1: | ||
return configBundleKey, true | ||
} | ||
return "", false | ||
} |
Oops, something went wrong.