Skip to content

Commit b387c19

Browse files
Addressed changes from PR - pullsecret parameter, nested virt only for openshift, removed withinstancetype func, change ddinfra name, etc
1 parent 77b4fc1 commit b387c19

8 files changed

Lines changed: 47 additions & 36 deletions

File tree

components/kubernetes/openshift.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
package kubernetes
22

33
import (
4-
"fmt"
5-
"os"
6-
74
"github.com/DataDog/test-infra-definitions/common/config"
85
"github.com/DataDog/test-infra-definitions/common/utils"
96
"github.com/DataDog/test-infra-definitions/components"
107
"github.com/DataDog/test-infra-definitions/components/command"
118
oscomp "github.com/DataDog/test-infra-definitions/components/os"
129
"github.com/DataDog/test-infra-definitions/components/remote"
1310
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
14-
sdkconfig "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
1511
)
1612

17-
func NewLocalOpenShiftCluster(env config.Env, name string, opts ...pulumi.ResourceOption) (*Cluster, error) {
13+
func NewLocalOpenShiftCluster(env config.Env, name string, pullSecretPath string, opts ...pulumi.ResourceOption) (*Cluster, error) {
1814
return components.NewComponent(env, name, func(clusterComp *Cluster) error {
15+
openShiftClusterName := env.CommonNamer().DisplayName(49)
1916
opts = utils.MergeOptions[pulumi.ResourceOption](opts, pulumi.Parent(clusterComp))
2017
commonEnvironment := env
2118
runner := command.NewLocalRunner(env, command.LocalRunnerArgs{
2219
OSCommand: command.NewUnixOSCommand(),
2320
})
2421

25-
pullSecretPath := os.Getenv("PULL_SECRET_PATH")
26-
if pullSecretPath == "" {
27-
return fmt.Errorf("PULL_SECRET_PATH environment variable is not set")
28-
}
29-
3022
crcSetup, err := runner.Command(commonEnvironment.CommonNamer().ResourceName("crc-setup"), &command.Args{
3123
Create: pulumi.String("crc setup"),
3224
}, opts...)
@@ -52,21 +44,18 @@ func NewLocalOpenShiftCluster(env config.Env, name string, opts ...pulumi.Resour
5244
}
5345

5446
clusterComp.KubeConfig = kubeConfigCmd.StdoutOutput()
55-
clusterComp.ClusterName = pulumi.String("openshift").ToStringOutput()
47+
clusterComp.ClusterName = openShiftClusterName.ToStringOutput()
5648
return nil
5749
}, opts...)
5850
}
5951

60-
func NewOpenShiftCluster(env config.Env, vm *remote.Host, name string, opts ...pulumi.ResourceOption) (*Cluster, error) {
52+
func NewOpenShiftCluster(env config.Env, vm *remote.Host, name string, pullSecretPath string, opts ...pulumi.ResourceOption) (*Cluster, error) {
6153
return components.NewComponent(env, name, func(clusterComp *Cluster) error {
6254
openShiftClusterName := env.CommonNamer().DisplayName(49)
6355
opts = utils.MergeOptions[pulumi.ResourceOption](opts, pulumi.Parent(clusterComp))
6456
runner := vm.OS.Runner()
6557
commonEnvironment := env
6658

67-
infraConfig := sdkconfig.New(env.Ctx(), "ddinfra")
68-
pullSecretPath := infraConfig.Require("openShiftPullSecretPath")
69-
7059
openShiftInstallBinary, err := InstallOpenShiftBinary(env, vm, opts...)
7160
if err != nil {
7261
return err

resources/gcp/compute/vm.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ func NewLinuxInstance(e gcp.Environment, name string, imageName string, instance
2424
Subnetwork: pulumi.String(e.DefaultSubnet()),
2525
},
2626
},
27-
Name: e.Namer.DisplayName(63, pulumi.String(name)),
28-
MachineType: pulumi.String(instanceType),
29-
AllowStoppingForUpdate: pulumi.Bool(true),
30-
AdvancedMachineFeatures: &compute.InstanceAdvancedMachineFeaturesArgs{
31-
EnableNestedVirtualization: pulumi.Bool(true),
32-
},
27+
Name: e.Namer.DisplayName(63, pulumi.String(name)),
28+
MachineType: pulumi.String(instanceType),
29+
AdvancedMachineFeatures: func() *compute.InstanceAdvancedMachineFeaturesArgs {
30+
if e.EnableNestedVirtualization() {
31+
return &compute.InstanceAdvancedMachineFeaturesArgs{
32+
EnableNestedVirtualization: pulumi.Bool(true),
33+
}
34+
}
35+
return nil
36+
}(),
3337
Tags: pulumi.StringArray{
3438
pulumi.String("appgate-gateway"),
3539
pulumi.String("nat-us-central1"),

resources/gcp/environment.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
DDInfraDefaultZoneNameParamName = "gcp/defaultZone"
2727
DDInfraDefautVMServiceAccountParamName = "gcp/defaultVMServiceAccount"
2828
DDInfraGKEEnableAutopilot = "gcp/gke/enableAutopilot"
29+
DDInfraOpenShiftPullSecretPath = "gcp/openshift/pullSecretPath"
30+
DDInfraEnableNestedVirtualization = "gcp/enableNestedVirtualization"
2931
)
3032

3133
type Environment struct {
@@ -170,3 +172,13 @@ func (e *Environment) Region() string {
170172
func (e *Environment) Zone() string {
171173
return e.GetStringWithDefault(e.InfraConfig, DDInfraDefaultZoneNameParamName, e.envDefault.gcp.zone)
172174
}
175+
176+
// OpenShiftPullSecretPath returns the path to the OpenShift pull secret file
177+
func (e *Environment) OpenShiftPullSecretPath() string {
178+
return e.InfraConfig.Get(DDInfraOpenShiftPullSecretPath)
179+
}
180+
181+
// EnableNestedVirtualization returns whether to enable nested virtualization
182+
func (e *Environment) EnableNestedVirtualization() bool {
183+
return e.GetBoolWithDefault(e.InfraConfig, DDInfraEnableNestedVirtualization, e.envDefault.ddInfra.openshift.nestedVirtualization)
184+
}

resources/gcp/environmentDefaults.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ type ddInfra struct {
2222
defaultSubnetName string
2323
defaultVMServiceAccount string
2424
gke ddInfraGKE
25+
openshift ddInfraOpenShift
2526
}
2627

2728
type ddInfraGKE struct {
2829
autopilot bool
2930
}
3031

32+
type ddInfraOpenShift struct {
33+
nestedVirtualization bool
34+
}
35+
3136
func getEnvironmentDefault(envName string) environmentDefault {
3237
switch envName {
3338
case agentSandboxEnv:
@@ -52,6 +57,7 @@ func agentSandboxDefault() environmentDefault {
5257
defaultSubnetName: "datadog-agent-sandbox-us-central1-private",
5358
defaultVMServiceAccount: "vmserviceaccount@datadog-agent-sandbox.iam.gserviceaccount.com",
5459
gke: ddInfraGKE{autopilot: false},
60+
openshift: ddInfraOpenShift{nestedVirtualization: false},
5561
},
5662
}
5763
}
@@ -69,6 +75,7 @@ func agentQaDefault() environmentDefault {
6975
defaultSubnetName: "datadog-agent-qa-us-central1-private",
7076
defaultVMServiceAccount: "vmserviceaccount@datadog-agent-qa.iam.gserviceaccount.com",
7177
gke: ddInfraGKE{autopilot: false},
78+
openshift: ddInfraOpenShift{nestedVirtualization: false},
7279
},
7380
}
7481
}

resources/local/environment.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
const (
1111
localNamerNamespace = "local"
1212
// local Infra (local)
13-
DDInfraDefaultPublicKeyPath = "local/defaultPublicKeyPath"
13+
DDInfraDefaultPublicKeyPath = "local/defaultPublicKeyPath"
14+
DDInfraOpenShiftPullSecretPath = "local/openshift/pullSecretPath"
1415
)
1516

1617
type Environment struct {
@@ -62,3 +63,8 @@ func (e *Environment) InternalRegistryFullImagePathExists(_ string) (bool, error
6263
func (e *Environment) DefaultPublicKeyPath() string {
6364
return e.InfraConfig.Get(DDInfraDefaultPublicKeyPath)
6465
}
66+
67+
// OpenShiftPullSecretPath returns the path to the OpenShift pull secret file
68+
func (e *Environment) OpenShiftPullSecretPath() string {
69+
return e.InfraConfig.Get(DDInfraOpenShiftPullSecretPath)
70+
}

scenarios/gcp/compute/vmargs.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,3 @@ func WithOSArch(osDesc os.Descriptor, arch os.Architecture) VMOption {
3434
return nil
3535
}
3636
}
37-
38-
// WithInstanceType set the instance type
39-
func WithInstanceType(instanceType string) VMOption {
40-
return func(p *vmArgs) error {
41-
p.instanceType = instanceType
42-
return nil
43-
}
44-
}

scenarios/gcp/openshiftvm/run.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package openshiftvm
22

33
import (
4-
localKubernetes "github.com/DataDog/test-infra-definitions/components/kubernetes"
4+
"github.com/DataDog/test-infra-definitions/components/kubernetes"
55
"github.com/DataDog/test-infra-definitions/components/os"
66
resGcp "github.com/DataDog/test-infra-definitions/resources/gcp"
77
"github.com/DataDog/test-infra-definitions/scenarios/gcp/compute"
@@ -16,16 +16,15 @@ func Run(ctx *pulumi.Context) error {
1616

1717
osDesc := os.DescriptorFromString("redhat:9", os.RedHat9)
1818
vm, err := compute.NewVM(gcpEnv, "openshift",
19-
compute.WithOS(osDesc),
20-
compute.WithInstanceType("n2-standard-8"))
19+
compute.WithOS(osDesc))
2120
if err != nil {
2221
return err
2322
}
2423
if err := vm.Export(ctx, nil); err != nil {
2524
return err
2625
}
2726

28-
openshiftCluster, err := localKubernetes.NewOpenShiftCluster(&gcpEnv, vm, "openshift")
27+
openshiftCluster, err := kubernetes.NewOpenShiftCluster(&gcpEnv, vm, "openshift", gcpEnv.OpenShiftPullSecretPath())
2928
if err != nil {
3029
return err
3130
}

tasks/gcp/openshift.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def create_openshift(
2424
ctx: Context,
2525
config_path: Optional[str] = None,
2626
stack_name: Optional[str] = None,
27-
interactive: Optional[bool] = True,
2827
pull_secret_path: Optional[str] = None,
28+
use_nested_virtualization: Optional[bool] = True,
2929
):
3030
"""
3131
Create an OpenShift environment.
@@ -46,7 +46,9 @@ def create_openshift(
4646
"scenario": scenario_name,
4747
"ddinfra:env": f"gcp/{cfg.get_gcp().account}",
4848
"ddinfra:gcp/defaultPublicKeyPath": cfg.get_gcp().publicKeyPath,
49-
"ddinfra:openShiftPullSecretPath": pull_secret_path,
49+
"ddinfra:gcp/openshift/pullSecretPath": pull_secret_path,
50+
"ddinfra:gcp/enableNestedVirtualization": use_nested_virtualization,
51+
"ddinfra:gcp/defaultInstanceType": "n2-standard-8",
5052
}
5153

5254
full_stack_name = deploy(

0 commit comments

Comments
 (0)