github.com/openshift/installer@v1.4.17/pkg/asset/imagebased/configimage/util_test.go (about)

     1  package configimage
     2  
     3  import (
     4  	"net"
     5  
     6  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     7  	"k8s.io/utils/ptr"
     8  	"sigs.k8s.io/yaml"
     9  
    10  	aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1"
    11  	"github.com/openshift/installer/pkg/asset/installconfig"
    12  	"github.com/openshift/installer/pkg/ipnet"
    13  	"github.com/openshift/installer/pkg/types"
    14  	"github.com/openshift/installer/pkg/types/imagebased"
    15  )
    16  
    17  const (
    18  	rawNMStateConfig = `
    19  interfaces:
    20    - name: eth0
    21      type: ethernet
    22      state: up
    23      mac-address: 00:00:00:00:00:00
    24      ipv4:
    25        enabled: true
    26        address:
    27          - ip: 192.168.122.2
    28            prefix-length: 23
    29        dhcp: false`
    30  
    31  	testCert = `-----BEGIN CERTIFICATE-----
    32  MIICYTCCAcqgAwIBAgIJAI2kA+uXAbhOMA0GCSqGSIb3DQEBCwUAMEgxCzAJBgNV
    33  BAYTAlVTMQswCQYDVQQIDAJDQTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzEUMBIG
    34  A1UECgwLUmVkIEhhdCBJbmMwHhcNMTkwMjEyMTkzMjUzWhcNMTkwMjEzMTkzMjUz
    35  WjBIMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFjAUBgNVBAcMDVNhbiBGcmFu
    36  Y2lzY28xFDASBgNVBAoMC1JlZCBIYXQgSW5jMIGfMA0GCSqGSIb3DQEBAQUAA4GN
    37  ADCBiQKBgQC+HOC0mKig/oINAKPo88LqxDJ4l7lozdLtp5oGeqWrLUXSfkvXAkQY
    38  2QYdvPAjpRfH7Ii7G0Asx+HTKdvula7B5fXDjc6NYKuEpTJZRV1ugntI97bozF/E
    39  C2BBmxxEnJN3+Xe8RYXMjz5Q4aqPw9vZhlWN+0hrREl1Ea/zHuWFIQIDAQABo1Mw
    40  UTAdBgNVHQ4EFgQUvTS1XjlvOdsufSyWxukyQu3LriEwHwYDVR0jBBgwFoAUvTS1
    41  XjlvOdsufSyWxukyQu3LriEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsF
    42  AAOBgQB9gFcOXnzJrM65QqxeCB9Z5l5JMjp45UFC9Bj2cgwDHP80Zvi4omlaacC6
    43  aavmnLd67zm9PbYDWRaOIWAMeB916Iwaw/v6I0jwhAk/VxX5Fl6cGlZu9jZ3zbFE
    44  2sDqkwzIuSjCG2A23s6d4M1S3IXCCydoCSLMu+WhLkbboK6jEg==
    45  -----END CERTIFICATE-----
    46  `
    47  )
    48  
    49  func defaultInstallConfig() *InstallConfig {
    50  	_, newCidr, err := net.ParseCIDR("192.168.111.0/24")
    51  	if err != nil {
    52  		return nil
    53  	}
    54  	_, machineNetCidr, err := net.ParseCIDR("10.10.11.0/24")
    55  	if err != nil {
    56  		return nil
    57  	}
    58  
    59  	return &InstallConfig{
    60  		AssetBase: installconfig.AssetBase{
    61  			Config: &types.InstallConfig{
    62  				ObjectMeta: metav1.ObjectMeta{
    63  					Name: "ocp-ibi",
    64  				},
    65  				BaseDomain: "testing.com",
    66  				PullSecret: testSecret,
    67  				SSHKey:     testSSHKey,
    68  				ControlPlane: &types.MachinePool{
    69  					Name:     "controlplane",
    70  					Replicas: ptr.To[int64](1),
    71  					Platform: types.MachinePoolPlatform{},
    72  				},
    73  				Networking: &types.Networking{
    74  					MachineNetwork: []types.MachineNetworkEntry{
    75  						{
    76  							CIDR: ipnet.IPNet{IPNet: *machineNetCidr},
    77  						},
    78  					},
    79  					ClusterNetwork: []types.ClusterNetworkEntry{
    80  						{
    81  							CIDR:       ipnet.IPNet{IPNet: *newCidr},
    82  							HostPrefix: 23,
    83  						},
    84  					},
    85  					ServiceNetwork: []ipnet.IPNet{
    86  						*ipnet.MustParseCIDR("172.30.0.0/16"),
    87  					},
    88  					NetworkType: "OVNKubernetes",
    89  				},
    90  			},
    91  		},
    92  	}
    93  }
    94  
    95  func imageBasedConfig() *ImageBasedConfig {
    96  	ibConfig := &ImageBasedConfig{
    97  		Config: &imagebased.Config{
    98  			ObjectMeta: metav1.ObjectMeta{
    99  				Name: "image-based-config",
   100  			},
   101  			TypeMeta: metav1.TypeMeta{
   102  				APIVersion: imagebased.ImageBasedConfigVersion,
   103  			},
   104  			Hostname:        "somehostname",
   105  			ReleaseRegistry: "quay.io",
   106  			NetworkConfig: aiv1beta1.NetConfig{
   107  				Raw: unmarshalJSON([]byte(rawNMStateConfig)),
   108  			},
   109  		},
   110  	}
   111  	return ibConfig
   112  }
   113  
   114  func unmarshalJSON(b []byte) []byte {
   115  	output, err := yaml.JSONToYAML(b)
   116  	if err != nil {
   117  		return nil
   118  	}
   119  	return output
   120  }