Skip to content

Commit

Permalink
HUB-33966: fixes the synopsysctl install issue in blackduck 2022.4.0 (#…
Browse files Browse the repository at this point in the history
…140)

* HUB-33966: adds size check based on blackduck version

* HUB-33966: changes readme

* HUB-33966: bump the dev snapshot version to 4.0.0-DEV-SNAPSHOT

* HUB-33966: adds test cases

* HUB-33966: adds legacy sizes

* HUB-33966: updates README.md for upgrade guidance

* HUB-33966: review feedback
  • Loading branch information
sig-zhengf committed May 9, 2022
1 parent 0b67de2 commit b8e168b
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pkg/api/.DS_Store
cmd/synopsysctl/*.key
_output/*
synopsysctl
config.json
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ go run main.go create blackduck $NS \
--certificate-file-path tls.crt \
--certificate-key-file-path tls.key \
--verbose-level trace \
--size small
--size 10sph
```

This will take a few minutes, so please be patient and watch `kubectl get pods -A`!
Expand Down Expand Up @@ -70,4 +70,7 @@ For customers using native command to deploy Black Duck, when upgrading Black Du
```
kubectl -n <namespace> delete deployment <namespace>-blackduck-webui
kubectl -n <namespace> delete service <namespace>-blackduck-webui
```
```

### Upgrade to 2022.4.0 and above
Black Duck version 2022.4.0 introduces new resource guidance. Synopsysctl 3.0.1 and above must be used, when upgrading Black Duck to version 2022.4.0 and above.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=3.0.0-DEV-SNAPSHOT
version=4.0.0-DEV-SNAPSHOT
75 changes: 75 additions & 0 deletions dev-tests/synopsysctl-tests/cmd_create/createBlackDuck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,78 @@ func TestCreateBlackDuck_NoPersistentStorage_LoadBalancer_BinaryAnalysis_SourceC
return
}
}

// TestCreateBlackDuck_SizesTest ...
func TestCreateBlackDuck_SizesTest(t *testing.T) {

var tests = []struct {
version string
size string
appResourcesPath string
} {
// case
{
version: "2022.2.0",
size: "small",
appResourcesPath: "https://sig-repo.synopsys.com/artifactory/sig-cloudnative/blackduck/blackduck-2022.2.0.tgz",
},
// case
{
version: "2022.4.0",
size: "small",
appResourcesPath: "https://sig-repo.synopsys.com/artifactory/sig-cloudnative/blackduck/blackduck-2022.4.0.tgz",
},
// case
{
version: "2022.4.0",
size: "10sph",
appResourcesPath: "https://sig-repo.synopsys.com/artifactory/sig-cloudnative/blackduck/blackduck-2022.4.0.tgz",
},
}

for _, test := range tests {
fmt.Printf("Testing BlackDuck Version '%s', Size '%s':\n", test.version, test.size)

blackDuckTester := tu.NewBlackDuckTester()

// Set Up
fmt.Printf("Creating Namespace\n")
_, err := util.CreateNamespace(tu.KubeClient, blackDuckTester.Namespace)
if err != nil {
t.Errorf("%s", err)
}

// Test
fmt.Printf("Creating Black Duck\n")

_, err = tu.Synospysctl("create blackduck %s -n %s --version %s --admin-password pass --user-password pass --seal-key abcdefghijklmnopqrstuvwxyz123456 --certificate-file-path %s --certificate-key-file-path %s --app-resources-path %s --size %s", blackDuckTester.Name, blackDuckTester.Namespace, test.version, tu.GetBlackDuckTLSCertPath(), tu.GetBlackDuckTLSKeyPath(), test.appResourcesPath, test.size)
if err != nil {
t.Errorf("%s", err)
return
}
blackDuckTester.WaitUntilReady()

fmt.Printf("Verifying Black Duck Configuration\n")
err = blackDuckTester.Verify()
if err != nil {
t.Errorf("%s", err)
return
}

// Tear Down
fmt.Printf("Deleting Black Duck\n")
_, err = tu.Synospysctl("delete blackduck %s -n %s", blackDuckTester.Name, blackDuckTester.Namespace)
if err != nil {
t.Errorf("%s", err)
return
}

fmt.Printf("Deleting Namespace\n")
err = util.DeleteNamespace(tu.KubeClient, blackDuckTester.Namespace)
if err != nil {
t.Errorf("%s", err)
return
}
}

}
26 changes: 8 additions & 18 deletions pkg/blackduck/ctl_blackduck.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (ctl *HelmValuesFromCobraFlags) AddCobraFlagsToCommand(cmd *cobra.Command,
cmd.Flags().StringVar(&ctl.flagTree.PersistentStorage, "persistent-storage", defaults.PersistentStorage, "If true, Black Duck has persistent storage [true|false]")
cmd.Flags().StringVar(&ctl.flagTree.PVCFilePath, "pvc-file-path", defaults.PVCFilePath, "Absolute path to a file containing a list of PVC json structs")
}
cmd.Flags().StringVar(&ctl.flagTree.Size, "size", defaults.Size, "Size of Black Duck [small|medium|large|x-large]")
cmd.Flags().StringVar(&ctl.flagTree.Size, "size", defaults.Size, "Size of Black Duck [small|medium|large|x-large|10sph|120sph|250sph|500sph|1000sph|1500sph|2000sph]")
cmd.Flags().StringVar(&ctl.flagTree.DeploymentResourcesFilePath, "deployment-resources-file-path", defaults.DeploymentResourcesFilePath, "Absolute path to a file containing a list of deployment Resources json structs\n")

// Expose UI
Expand Down Expand Up @@ -238,24 +238,14 @@ func (ctl *HelmValuesFromCobraFlags) AddCobraFlagsToCommand(cmd *cobra.Command,
cmd.Flags().BoolVar(&ctl.flagTree.IsAzure, "is-azure", defaults.IsAzure, "If true, deployment will be configured for Azure")
}

func isValidSize(size string) bool {
switch strings.ToLower(size) {
case
"",
"small",
"medium",
"large",
"x-large":
return true
}
return false
}

// CheckValuesFromFlags returns an error if a value stored in the struct will not be able to be used
func (ctl *HelmValuesFromCobraFlags) CheckValuesFromFlags(flagset *pflag.FlagSet) error {
func (ctl *HelmValuesFromCobraFlags) CheckValuesFromFlags(flagset *pflag.FlagSet, version string) error {
if FlagWasSet(flagset, "size") {
if !isValidSize(ctl.flagTree.Size) {
return fmt.Errorf("size must be 'small', 'medium', 'large' or 'x-large'")
if len(ctl.flagTree.Size) > 0 {
_, err := util.GetSizeYAMLFileName(ctl.flagTree.Size, version)
if err != nil {
return err
}
}
}
if FlagWasSet(flagset, "expose-ui") {
Expand Down Expand Up @@ -347,7 +337,7 @@ func FlagWasSet(flagset *pflag.FlagSet, flagName string) bool {
// GenerateHelmFlagsFromCobraFlags checks each flag in synopsysctl and updates the map to
// contain the corresponding helm chart field and value
func (ctl *HelmValuesFromCobraFlags) GenerateHelmFlagsFromCobraFlags(flagset *pflag.FlagSet) (map[string]interface{}, error) {
err := ctl.CheckValuesFromFlags(flagset)
err := ctl.CheckValuesFromFlags(flagset, globals.BlackDuckVersion)
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/blackduck/ctl_blackduck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ func TestSetCRSpecFieldByFlag(t *testing.T) {
},
},
// case
{
flagName: "size",
changedCtl: &HelmValuesFromCobraFlags{
flagTree: FlagTree{
Size: "10sph",
},
},
changedArgs: map[string]interface{}{
"size": "10sph",
},
},
// case
{
flagName: "expose-ui",
changedCtl: &HelmValuesFromCobraFlags{
Expand Down
12 changes: 10 additions & 2 deletions pkg/synopsysctl/cmd_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ var createBlackDuckCmd = &cobra.Command{
}
size, found := helmValuesMap["size"]
if found && len(size.(string)) > 0 {
extraFiles = append(extraFiles, fmt.Sprintf("%s.yaml", strings.ToLower(size.(string))))
yml, err := util.GetSizeYAMLFileName(size.(string), globals.BlackDuckVersion)
if err != nil {
return err
}
extraFiles = append(extraFiles, yml)
}

// Create initial resources
Expand Down Expand Up @@ -493,7 +497,11 @@ var createBlackDuckNativeCmd = &cobra.Command{
}
size, found := helmValuesMap["size"]
if found && len(size.(string)) > 0 {
extraFiles = append(extraFiles, fmt.Sprintf("%s.yaml", strings.ToLower(size.(string))))
yml, err := util.GetSizeYAMLFileName(size.(string), globals.BlackDuckVersion)
if err != nil {
return err
}
extraFiles = append(extraFiles, yml)
}

// Create initial resources
Expand Down
12 changes: 10 additions & 2 deletions pkg/synopsysctl/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,18 @@ var updateBlackDuckCmd = &cobra.Command{

var sizeYAMLFileNameInChart string
if cmd.Flag("size").Changed {
sizeYAMLFileNameInChart = fmt.Sprintf("%s.yaml", cmd.Flag("size").Value.String())
yml, err := util.GetSizeYAMLFileName(cmd.Flag("size").Value.String(), globals.BlackDuckVersion)
if err != nil {
return err
}
sizeYAMLFileNameInChart = yml
} else {
if size, found := instance.Config["size"]; found && len(size.(string)) > 0 {
sizeYAMLFileNameInChart = fmt.Sprintf("%s.yaml", size.(string))
yml, err := util.GetSizeYAMLFileName(size.(string), globals.BlackDuckVersion)
if err != nil {
return err
}
sizeYAMLFileNameInChart = yml
}
}

Expand Down
45 changes: 45 additions & 0 deletions pkg/util/helm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,48 @@ func setStringPtrInHelmValueInMap(valueMapPointer map[string]interface{}, keyLis
SetHelmValueInMap(valueMapPointer, keyList, *value)
}
}

func isValidGen02Size(size string) bool {
switch strings.ToLower(size) {
case
"small",
"medium",
"large",
"x-large":
return true
}
return false
}

func isValidGen03Size(size string) bool {
switch strings.ToLower(size) {
case
"10sph",
"120sph",
"250sph",
"500sph",
"1000sph",
"1500sph",
"2000sph":
return true
}
return false
}

func GetSizeYAMLFileName(size string, version string) (string, error) {
if CompareVersions(version, "2022.4.0") < 0 {
if isValidGen02Size(size) {
return fmt.Sprintf("%s.yaml", strings.ToLower(size)), nil
} else {
return "", fmt.Errorf("size must be 'small', 'medium', 'large' or 'x-large'")
}
} else {
if isValidGen02Size(size) {
return fmt.Sprintf("sizes-gen02/%s.yaml", strings.ToLower(size)), nil
} else if isValidGen03Size(size) {
return fmt.Sprintf("sizes-gen03/%s.yaml", strings.ToLower(size)), nil
} else {
return "", fmt.Errorf("size must be 'small', 'medium', 'large', 'x-large', '10sph', '120sph', '250sph', '500sph', '1000sph', '1500sph' or '2000sph'")
}
}
}

0 comments on commit b8e168b

Please sign in to comment.