/
generator.go
97 lines (85 loc) · 3.55 KB
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// package contains the generators for provider specific shoot configuration
package main
import (
"flag"
"os"
"reflect"
"github.com/gardener/gardener-extension-provider-azure/pkg/apis/azure/v1alpha1"
"github.com/gardener/gardener/extensions/test/tm/generator"
"github.com/pkg/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
log "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
var (
infrastructureProviderConfigPath = flag.String("infrastructure-provider-config-filepath", "", "filepath to the provider specific infrastructure config")
controlplaneProviderConfigPath = flag.String("controlplane-provider-config-filepath", "", "filepath to the provider specific controlplane config")
networkVnetCidr = flag.String("network-vnet-cidr", "10.250.0.0/16", "vnet network cidr")
networkWorkerCidr = flag.String("network-worker-cidr", "10.250.0.0/19", "worker network cidr")
zoned = flag.Bool("zoned", false, "shoot uses multiple zones")
)
func main() {
log.SetLogger(zap.Logger(false))
logger := log.Log.WithName("azure-generator")
flag.Parse()
if err := validate(); err != nil {
logger.Error(err, "error validating input flags")
os.Exit(1)
}
infra := v1alpha1.InfrastructureConfig{
TypeMeta: v1.TypeMeta{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: reflect.TypeOf(v1alpha1.InfrastructureConfig{}).Name(),
},
Networks: v1alpha1.NetworkConfig{
VNet: v1alpha1.VNet{
CIDR: networkVnetCidr,
},
Workers: *networkWorkerCidr,
},
Zoned: *zoned,
}
cp := v1alpha1.ControlPlaneConfig{
TypeMeta: v1.TypeMeta{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: reflect.TypeOf(v1alpha1.ControlPlaneConfig{}).Name(),
},
}
if err := generator.MarshalAndWriteConfig(*infrastructureProviderConfigPath, infra); err != nil {
logger.Error(err, "unable to write infrastructure config")
os.Exit(1)
}
if err := generator.MarshalAndWriteConfig(*controlplaneProviderConfigPath, cp); err != nil {
logger.Error(err, "unable to write infrastructure config")
os.Exit(1)
}
logger.Info("successfully written azure provider configuration", "infra", *infrastructureProviderConfigPath, "controlplane", *controlplaneProviderConfigPath)
}
func validate() error {
if err := generator.ValidateString(infrastructureProviderConfigPath); err != nil {
return errors.Wrap(err, "error validating infrastructure provider config path")
}
if err := generator.ValidateString(controlplaneProviderConfigPath); err != nil {
return errors.Wrap(err, "error validating controlplane provider config path")
}
if err := generator.ValidateString(networkVnetCidr); err != nil {
return errors.Wrap(err, "error validating vnet CIDR")
}
if err := generator.ValidateString(networkWorkerCidr); err != nil {
return errors.Wrap(err, "error validating worker CIDR")
}
return nil
}