-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scorecard: add bundle metadata #3474
Merged
estroz
merged 1 commit into
operator-framework:master
from
estroz:feature/scorecard-metadata
Jul 21, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
estroz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we please use
sigs.k8s.io/yaml
instead of this one for we still closer as possible to rip all these other modules to dealing with yaml as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That isn't possible until we bump operator-registry versions since the struct being marshalled only has
yaml
tags. I don't think we'll bump versions until after v1.0.