Skip to content
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

commands/.../scorecard: optionally use only a CSV manifest when deployed with OLM #1044

Merged
merged 42 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
821bac7
* pkg/scaffold/olm-catalog/csv*.go: use afero Fs in CSV generation
estroz Jan 24, 2019
6a5567d
Merge branch 'master' into inject-fs
estroz Jan 25, 2019
70162b3
pkg/.../csv.go: getFS instead of naked field ref
estroz Jan 25, 2019
5632f73
internal/.../file_util.go: {NewFileWriter,Get}(FS)? instead of naked …
estroz Jan 25, 2019
977cb29
Merge branch 'master' into inject-fs
estroz Jan 28, 2019
a1c57f7
initFS in getFS
estroz Jan 29, 2019
70cbb26
remove os.Stat and check IfNotExists after reading file
estroz Jan 29, 2019
430dd50
Merge branch 'master' into inject-fs
estroz Jan 31, 2019
5dd0dcf
commands/.../scorecard/*: optionally get data from CSV only
estroz Feb 1, 2019
5157332
add ClusterRole to namespaced manifest
estroz Feb 1, 2019
c951783
add olm-deployed scorecard test
estroz Feb 1, 2019
789625b
Merge branch 'master' into olm-scorecard-integration
estroz Feb 1, 2019
7bea4a2
fix scaffold.CRDsDir name
estroz Feb 1, 2019
0cd061c
Merge branch 'master' into olm-scorecard-integration
estroz Feb 1, 2019
6bfc5d0
Merge branch 'master' into olm-scorecard-integration
estroz Feb 1, 2019
d2c7773
only get CR's from alm-examples if no CR is passed in
estroz Feb 1, 2019
dc872e8
add license header
estroz Feb 1, 2019
4e53bdd
bump expected number of scorecard points (CR example was added to CSV)
estroz Feb 1, 2019
761d4a4
add crd-dir flag
estroz Feb 1, 2019
14f2705
fix panic
estroz Feb 2, 2019
73ea529
pluralize crd/CRD
estroz Feb 5, 2019
4a72c06
* commands/.../scorecard/scorecard.go: grammar
estroz Feb 5, 2019
8c04d8d
Merge branch 'test-scorecard-config' into olm-scorecard-integration
estroz Feb 5, 2019
b96617a
create resources correctly when only using CSV
estroz Feb 5, 2019
60834b1
cleanup and reverting a few changes
estroz Feb 5, 2019
50c6502
use CRDsDir as flag default
estroz Feb 5, 2019
faf9362
Merge branch 'master' into olm-scorecard-integration
estroz Feb 5, 2019
e226820
deduplicate flags, add timeout and points to scorecard subcommand tests
estroz Feb 5, 2019
c30dc9a
fix unit test
estroz Feb 5, 2019
6ba075f
Merge branch 'master' into olm-scorecard-integration
estroz Feb 6, 2019
d294464
use --init-timeout for 3rd scorecard test
estroz Feb 6, 2019
1fb67df
revert unit test fix
estroz Feb 6, 2019
81e425f
commands/.../scorecard/*: conditionally create resources from CSV
estroz Feb 12, 2019
22e546d
Merge branch 'master' into olm-scorecard-integration
estroz Feb 12, 2019
cc9aa07
allow creation of operator resources outside of SDK
estroz Feb 13, 2019
6bc13eb
Merge branch 'master' into olm-scorecard-integration
estroz Feb 13, 2019
38fac62
get deploymentName from CSV if olm-deployed is true
estroz Feb 13, 2019
2d89e15
Merge branch 'master' into olm-scorecard-integration
estroz Feb 18, 2019
86c22cc
commands/.../scorecard*: if --olm-deployed, get proxyPod outside of r…
estroz Feb 19, 2019
963c418
Merge branch 'master' into olm-scorecard-integration
estroz Feb 27, 2019
6a28955
PR updates
estroz Feb 28, 2019
4e21ef2
CHANGELOG.md/docs/sdk-cli-reference.md: add --olm-deployed flag
estroz Feb 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- New flags for [`operator-sdk new --type=helm`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#new), which can be used to populate the project with an existing chart. ([#949](https://github.com/operator-framework/operator-sdk/pull/949))
- Command [`operator-sdk olm-catalog`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#olm-catalog) flag `--update-crds` optionally copies CRD's from `deploy/crds` when creating a new CSV or updating an existing CSV, and `--from-version` uses another versioned CSV manifest as a base for a new CSV version. ([#1016](https://github.com/operator-framework/operator-sdk/pull/1016))
- New flag `--olm-deployed` to direct the [`scorecard`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#scorecard) command to only use the CSV at `--csv-path` for manifest data, except for those provided to `--cr-manifest`. ([#1044](https://github.com/operator-framework/operator-sdk/pull/1044))

### Changed

Expand Down
7 changes: 4 additions & 3 deletions commands/operator-sdk/cmd/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ import (
"fmt"
"strings"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/scorecard"
"github.com/operator-framework/operator-sdk/pkg/scaffold"
"github.com/operator-framework/operator-sdk/version"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/scorecard"
"github.com/operator-framework/operator-sdk/version"
)

// scorecardConfig stores all scorecard config passed as flags
type scorecardConfig struct {
namespace string
kubeconfigPath string
initTimeout int
olmDeployed bool
csvPath string
basicTests bool
olmTests bool
Expand Down Expand Up @@ -61,6 +61,7 @@ func NewScorecardCmd() *cobra.Command {
scorecardCmd.Flags().StringVar(&scConf.namespace, scorecard.NamespaceOpt, "", "Namespace of custom resource created in cluster")
scorecardCmd.Flags().StringVar(&scConf.kubeconfigPath, scorecard.KubeconfigOpt, "", "Path to kubeconfig of custom resource created in cluster")
scorecardCmd.Flags().IntVar(&scConf.initTimeout, scorecard.InitTimeoutOpt, 10, "Timeout for status block on CR to be created in seconds")
scorecardCmd.Flags().BoolVar(&scConf.olmDeployed, scorecard.OlmDeployedOpt, false, "The OLM has deployed the operator. Use only the CSV for test data")
scorecardCmd.Flags().StringVar(&scConf.csvPath, scorecard.CSVPathOpt, "", "Path to CSV being tested")
scorecardCmd.Flags().BoolVar(&scConf.basicTests, scorecard.BasicTestsOpt, true, "Enable basic operator checks")
scorecardCmd.Flags().BoolVar(&scConf.olmTests, scorecard.OLMTestsOpt, true, "Enable OLM integration checks")
Expand Down
2 changes: 1 addition & 1 deletion commands/operator-sdk/cmd/scorecard/basic_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// status blocks exist or return an error after the timeout.
func checkSpecAndStat(runtimeClient client.Client, obj *unstructured.Unstructured, noStore bool) error {
testSpec := scorecardTest{testType: basicOperator, name: "Spec Block Exists", maximumPoints: 1}
testStat := scorecardTest{testType: basicOperator, name: "Status Block Exist", maximumPoints: 1}
testStat := scorecardTest{testType: basicOperator, name: "Status Block Exists", maximumPoints: 1}
err := wait.Poll(time.Second*1, time.Second*time.Duration(viper.GetInt64(InitTimeoutOpt)), func() (bool, error) {
err := runtimeClient.Get(context.TODO(), types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, obj)
if err != nil {
Expand Down
69 changes: 40 additions & 29 deletions commands/operator-sdk/cmd/scorecard/resource_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,9 @@ func createFromYAMLFile(yamlPath string) error {
}
addResourceCleanup(obj, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()})
if obj.GetKind() == "Deployment" {
dep := &appsv1.Deployment{}
err = runtimeClient.Get(context.TODO(), types.NamespacedName{Namespace: viper.GetString(NamespaceOpt), Name: deploymentName}, dep)
proxyPod, err = getPodFromDeployment(deploymentName, viper.GetString(NamespaceOpt))
if err != nil {
return fmt.Errorf("failed to get newly created deployment: %v", err)
}
set := labels.Set(dep.Spec.Selector.MatchLabels)
// in some cases, the pod from the old deployment will be picked up instead of the new one
err = wait.PollImmediate(time.Second*1, time.Second*60, func() (bool, error) {
pods := &v1.PodList{}
err = runtimeClient.List(context.TODO(), &client.ListOptions{LabelSelector: set.AsSelector()}, pods)
if err != nil {
return false, fmt.Errorf("failed to get list of pods in deployment: %v", err)
}
// make sure the pods exist
// there should only be 1 pod per deployment
if len(pods.Items) == 1 {
// if the pod has a deletion timestamp, it is the old pod; wait for pod with no deletion timestamp
if pods.Items[0].GetDeletionTimestamp() == nil {
proxyPod = &pods.Items[0]
return true, nil
}
} else {
log.Debug("Operator deployment has more than 1 pod")
}
return false, nil
})
if err != nil {
return fmt.Errorf("failed to get proxyPod: %s", err)
return err
}
}
}
Expand All @@ -168,6 +143,41 @@ func createFromYAMLFile(yamlPath string) error {
return nil
}

// getPodFromDeployment returns a deployment depName's pod in namespace.
func getPodFromDeployment(depName, namespace string) (pod *v1.Pod, err error) {
dep := &appsv1.Deployment{}
err = runtimeClient.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: depName}, dep)
if err != nil {
return nil, fmt.Errorf("failed to get newly created deployment: %v", err)
}
set := labels.Set(dep.Spec.Selector.MatchLabels)
// In some cases, the pod from the old deployment will be picked up
// instead of the new one.
err = wait.PollImmediate(time.Second*1, time.Second*60, func() (bool, error) {
pods := &v1.PodList{}
err = runtimeClient.List(context.TODO(), &client.ListOptions{LabelSelector: set.AsSelector()}, pods)
if err != nil {
return false, fmt.Errorf("failed to get list of pods in deployment: %v", err)
}
// Make sure the pods exist. There should only be 1 pod per deployment.
if len(pods.Items) == 1 {
// If the pod has a deletion timestamp, it is the old pod; wait for
// pod with no deletion timestamp
if pods.Items[0].GetDeletionTimestamp() == nil {
pod = &pods.Items[0]
return true, nil
}
} else {
log.Debug("Operator deployment has more than 1 pod")
}
return false, nil
})
if err != nil {
return nil, fmt.Errorf("failed to get proxyPod: %s", err)
}
return pod, nil
}

// createKubeconfigSecret creates the secret that will be mounted in the operator's container and contains
// the kubeconfig for communicating with the proxy
func createKubeconfigSecret() error {
Expand Down Expand Up @@ -249,7 +259,7 @@ func addProxyContainer(dep *appsv1.Deployment) {
pullPolicy = v1.PullAlways
}
dep.Spec.Template.Spec.Containers = append(dep.Spec.Template.Spec.Containers, v1.Container{
Name: "scorecard-proxy",
Name: scorecardContainerName,
Image: viper.GetString(ProxyImageOpt),
ImagePullPolicy: pullPolicy,
Command: []string{"scorecard-proxy"},
Expand Down Expand Up @@ -340,7 +350,8 @@ func getProxyLogs() (string, error) {
if err != nil {
return "", fmt.Errorf("failed to create kubeclient: %v", err)
}
req := kubeclient.CoreV1().Pods(proxyPod.GetNamespace()).GetLogs(proxyPod.GetName(), &v1.PodLogOptions{Container: "scorecard-proxy"})
logOpts := &v1.PodLogOptions{Container: scorecardContainerName}
req := kubeclient.CoreV1().Pods(proxyPod.GetNamespace()).GetLogs(proxyPod.GetName(), logOpts)
readCloser, err := req.Stream()
if err != nil {
return "", fmt.Errorf("failed to get logs: %v", err)
Expand Down
Loading