Skip to content

Commit d8108ef

Browse files
committed
Merge branch 'master' into crd-validation
2 parents b46c19a + b1d5e62 commit d8108ef

File tree

30 files changed

+659
-227
lines changed

30 files changed

+659
-227
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ x_base_steps:
1616
# that it can properly exit the test early with success
1717
- source hack/ci/check-doc-only-update.sh
1818
- curl -Lo dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x dep && sudo mv dep /usr/local/bin/
19-
- travis_retry dep ensure
19+
- travis_retry dep ensure -v
2020

2121
# Base go, ansbile, and helm job
2222
- &test

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Changed
1010

11+
- In new Helm operator projects, the scaffolded CR `spec` field now contains the default values.yaml from the generated chart. ([#967](https://github.com/operator-framework/operator-sdk/pull/967))
12+
1113
### Deprecated
1214

1315
### Removed

Gopkg.lock

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

commands/operator-sdk/cmd/new.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ func doHelmScaffold() error {
261261
return err
262262
}
263263

264+
chart, err := helm.CreateChartForResource(resource, cfg.AbsProjectPath)
265+
if err != nil {
266+
log.Fatalf("Failed to create initial helm chart for resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err)
267+
}
268+
269+
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.GetMetadata().GetName(), "values.yaml")
270+
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, chart.GetValues().GetRaw())
271+
264272
s := &scaffold.Scaffold{}
265273
err = s.Execute(cfg,
266274
&helm.Dockerfile{},
@@ -270,16 +278,15 @@ func doHelmScaffold() error {
270278
&scaffold.RoleBinding{IsClusterScoped: isClusterScoped},
271279
&helm.Operator{IsClusterScoped: isClusterScoped},
272280
&scaffold.CRD{Resource: resource},
273-
&scaffold.CR{Resource: resource},
281+
&scaffold.CR{
282+
Resource: resource,
283+
Spec: crSpec,
284+
},
274285
)
275286
if err != nil {
276287
return fmt.Errorf("new helm scaffold failed: (%v)", err)
277288
}
278289

279-
if err := helm.CreateChartForResource(resource, cfg.AbsProjectPath); err != nil {
280-
return fmt.Errorf("failed to create initial helm chart for resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err)
281-
}
282-
283290
if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil {
284291
return fmt.Errorf("failed to update the RBAC manifest for resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err)
285292
}

commands/operator-sdk/cmd/scorecard.go

+37-15
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,31 @@ import (
2020

2121
log "github.com/sirupsen/logrus"
2222
"github.com/spf13/cobra"
23+
"github.com/spf13/viper"
2324

2425
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/scorecard"
2526
"github.com/operator-framework/operator-sdk/version"
2627
)
2728

29+
// scorecardConfig stores all scorecard config passed as flags
30+
type scorecardConfig struct {
31+
namespace string
32+
kubeconfigPath string
33+
initTimeout int
34+
csvPath string
35+
basicTests bool
36+
olmTests bool
37+
tenantTests bool
38+
namespacedManifest string
39+
globalManifest string
40+
crManifest string
41+
proxyImage string
42+
proxyPullPolicy string
43+
verbose bool
44+
}
45+
46+
var scConf scorecardConfig
47+
2848
func NewScorecardCmd() *cobra.Command {
2949
scorecardCmd := &cobra.Command{
3050
Use: "scorecard",
@@ -34,21 +54,23 @@ func NewScorecardCmd() *cobra.Command {
3454
RunE: scorecard.ScorecardTests,
3555
}
3656

37-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.Namespace, "namespace", "", "Namespace of custom resource created in cluster")
38-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.KubeconfigPath, "kubeconfig", "", "Path to kubeconfig of custom resource created in cluster")
39-
scorecardCmd.Flags().IntVar(&scorecard.SCConf.InitTimeout, "init-timeout", 10, "Timeout for status block on CR to be created in seconds")
40-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.CSVPath, "csv-path", "", "Path to CSV being tested")
41-
scorecardCmd.Flags().BoolVar(&scorecard.SCConf.BasicTests, "basic-tests", true, "Enable basic operator checks")
42-
scorecardCmd.Flags().BoolVar(&scorecard.SCConf.OLMTests, "olm-tests", true, "Enable OLM integration checks")
43-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.NamespacedManifest, "namespaced-manifest", "", "Path to manifest for namespaced resources (e.g. RBAC and Operator manifest)")
44-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.GlobalManifest, "global-manifest", "", "Path to manifest for Global resources (e.g. CRD manifests)")
45-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.CRManifest, "cr-manifest", "", "Path to manifest for Custom Resource")
46-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.ProxyImage, "proxy-image", fmt.Sprintf("quay.io/operator-framework/scorecard-proxy:%s", strings.TrimSuffix(version.Version, "+git")), "Image name for scorecard proxy")
47-
scorecardCmd.Flags().StringVar(&scorecard.SCConf.ProxyPullPolicy, "proxy-pull-policy", "Always", "Pull policy for scorecard proxy image")
48-
scorecardCmd.Flags().BoolVar(&scorecard.SCConf.Verbose, "verbose", false, "Enable verbose logging")
49-
// Since it's difficult to handle multiple CRs, we will require users to specify what CR they want to test; we can handle this better in the future
50-
if err := scorecardCmd.MarkFlagRequired("cr-manifest"); err != nil {
51-
log.Fatalf("Failed to mark `cr-manifest` flag for `scorecard` subcommand as required")
57+
scorecardCmd.Flags().StringVar(&scorecard.ScorecardConf, scorecard.ConfigOpt, "", "config file (default is <project_dir>/.osdk-scorecard.yaml)")
58+
scorecardCmd.Flags().StringVar(&scConf.namespace, scorecard.NamespaceOpt, "", "Namespace of custom resource created in cluster")
59+
scorecardCmd.Flags().StringVar(&scConf.kubeconfigPath, scorecard.KubeconfigOpt, "", "Path to kubeconfig of custom resource created in cluster")
60+
scorecardCmd.Flags().IntVar(&scConf.initTimeout, scorecard.InitTimeoutOpt, 10, "Timeout for status block on CR to be created in seconds")
61+
scorecardCmd.Flags().StringVar(&scConf.csvPath, scorecard.CSVPathOpt, "", "Path to CSV being tested")
62+
scorecardCmd.Flags().BoolVar(&scConf.basicTests, scorecard.BasicTestsOpt, true, "Enable basic operator checks")
63+
scorecardCmd.Flags().BoolVar(&scConf.olmTests, scorecard.OLMTestsOpt, true, "Enable OLM integration checks")
64+
scorecardCmd.Flags().BoolVar(&scConf.tenantTests, scorecard.TenantTestsOpt, false, "Enable good tenant checks")
65+
scorecardCmd.Flags().StringVar(&scConf.namespacedManifest, scorecard.NamespacedManifestOpt, "", "Path to manifest for namespaced resources (e.g. RBAC and Operator manifest)")
66+
scorecardCmd.Flags().StringVar(&scConf.globalManifest, scorecard.GlobalManifestOpt, "", "Path to manifest for Global resources (e.g. CRD manifests)")
67+
scorecardCmd.Flags().StringVar(&scConf.crManifest, scorecard.CRManifestOpt, "", "Path to manifest for Custom Resource (required)")
68+
scorecardCmd.Flags().StringVar(&scConf.proxyImage, scorecard.ProxyImageOpt, fmt.Sprintf("quay.io/operator-framework/scorecard-proxy:%s", strings.TrimSuffix(version.Version, "+git")), "Image name for scorecard proxy")
69+
scorecardCmd.Flags().StringVar(&scConf.proxyPullPolicy, scorecard.ProxyPullPolicyOpt, "Always", "Pull policy for scorecard proxy image")
70+
scorecardCmd.Flags().BoolVar(&scConf.verbose, scorecard.VerboseOpt, false, "Enable verbose logging")
71+
72+
if err := viper.BindPFlags(scorecardCmd.Flags()); err != nil {
73+
log.Fatalf("Failed to bind scorecard flags to viper: %v", err)
5274
}
5375

5476
return scorecardCmd

commands/operator-sdk/cmd/scorecard/basic_tests.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/operator-framework/operator-sdk/internal/util/fileutil"
2828

2929
log "github.com/sirupsen/logrus"
30+
"github.com/spf13/viper"
3031
appsv1 "k8s.io/api/apps/v1"
3132
v1 "k8s.io/api/core/v1"
3233
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -43,7 +44,7 @@ import (
4344
func checkSpecAndStat(runtimeClient client.Client, obj *unstructured.Unstructured, noStore bool) error {
4445
testSpec := scorecardTest{testType: basicOperator, name: "Spec Block Exists", maximumPoints: 1}
4546
testStat := scorecardTest{testType: basicOperator, name: "Status Block Exist", maximumPoints: 1}
46-
err := wait.Poll(time.Second*1, time.Second*time.Duration(SCConf.InitTimeout), func() (bool, error) {
47+
err := wait.Poll(time.Second*1, time.Second*time.Duration(viper.GetInt64(InitTimeoutOpt)), func() (bool, error) {
4748
err := runtimeClient.Get(context.TODO(), types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, obj)
4849
if err != nil {
4950
return false, fmt.Errorf("error getting custom resource: %v", err)

commands/operator-sdk/cmd/scorecard/resource_handler.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
proxyConf "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/kubeconfig"
2727
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
28+
"github.com/spf13/viper"
2829

2930
"github.com/ghodss/yaml"
3031
log "github.com/sirupsen/logrus"
@@ -56,7 +57,7 @@ func yamlToUnstructured(yamlPath string) (*unstructured.Unstructured, error) {
5657
return nil, fmt.Errorf("failed to unmarshal custom resource manifest to unstructured: %s", err)
5758
}
5859
// set the namespace
59-
obj.SetNamespace(SCConf.Namespace)
60+
obj.SetNamespace(viper.GetString(NamespaceOpt))
6061
return obj, nil
6162
}
6263

@@ -81,7 +82,7 @@ func createFromYAMLFile(yamlPath string) error {
8182
if err := obj.UnmarshalJSON(jsonSpec); err != nil {
8283
return fmt.Errorf("could not unmarshal resource spec: %v", err)
8384
}
84-
obj.SetNamespace(SCConf.Namespace)
85+
obj.SetNamespace(viper.GetString(NamespaceOpt))
8586

8687
// dirty hack to merge scorecard proxy into operator deployment; lots of serialization and deserialization
8788
if obj.GetKind() == "Deployment" {
@@ -136,7 +137,7 @@ func createFromYAMLFile(yamlPath string) error {
136137
// the kubeconfig for communicating with the proxy
137138
func createKubeconfigSecret() error {
138139
kubeconfigMap := make(map[string][]byte)
139-
kc, err := proxyConf.Create(metav1.OwnerReference{Name: "scorecard"}, "http://localhost:8889", SCConf.Namespace)
140+
kc, err := proxyConf.Create(metav1.OwnerReference{Name: "scorecard"}, "http://localhost:8889", viper.GetString(NamespaceOpt))
140141
if err != nil {
141142
return err
142143
}
@@ -157,7 +158,7 @@ func createKubeconfigSecret() error {
157158
kubeconfigSecret := &v1.Secret{
158159
ObjectMeta: metav1.ObjectMeta{
159160
Name: "scorecard-kubeconfig",
160-
Namespace: SCConf.Namespace,
161+
Namespace: viper.GetString(NamespaceOpt),
161162
},
162163
Data: kubeconfigMap,
163164
}
@@ -199,8 +200,9 @@ func addMountKubeconfigSecret(dep *appsv1.Deployment) {
199200

200201
// addProxyContainer adds the container spec for the scorecard-proxy to the deployment's podspec
201202
func addProxyContainer(dep *appsv1.Deployment) {
203+
pullPolicyString := viper.GetString(ProxyPullPolicyOpt)
202204
var pullPolicy v1.PullPolicy
203-
switch SCConf.ProxyPullPolicy {
205+
switch pullPolicyString {
204206
case "Always":
205207
pullPolicy = v1.PullAlways
206208
case "Never":
@@ -213,7 +215,7 @@ func addProxyContainer(dep *appsv1.Deployment) {
213215
}
214216
dep.Spec.Template.Spec.Containers = append(dep.Spec.Template.Spec.Containers, v1.Container{
215217
Name: "scorecard-proxy",
216-
Image: SCConf.ProxyImage,
218+
Image: viper.GetString(ProxyImageOpt),
217219
ImagePullPolicy: pullPolicy,
218220
Command: []string{"scorecard-proxy"},
219221
Env: []v1.EnvVar{{

0 commit comments

Comments
 (0)