Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit a52d583

Browse files
committed
update import
1 parent 65d5e2a commit a52d583

File tree

7 files changed

+75
-406
lines changed

7 files changed

+75
-406
lines changed

.idea/workspace.xml

Lines changed: 0 additions & 337 deletions
This file was deleted.

pkg/crinit/aggregated/aggregated.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"k8s.io/client-go/util/cert"
3434
"k8s.io/cluster-registry/pkg/apis/clusterregistry/v1alpha1"
3535
"k8s.io/cluster-registry/pkg/crinit/util"
36+
"k8s.io/cluster-registry/pkg/crinit/options"
37+
"k8s.io/cluster-registry/pkg/crinit/common"
3638
apiregv1beta1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
3739
apiregclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
3840

@@ -97,12 +99,12 @@ var (
9799
)
98100

99101
type aggregatedClusterRegistryOptions struct {
100-
util.SubcommandOptions
102+
options.SubcommandOptions
101103
apiServerServiceTypeString string
102104
}
103105

104106
func (o *aggregatedClusterRegistryOptions) Bind(flags *pflag.FlagSet) {
105-
flags.StringVar(&o.apiServerServiceTypeString, util.APIServerServiceTypeFlag,
107+
flags.StringVar(&o.apiServerServiceTypeString, options.APIServerServiceTypeFlag,
106108
string(v1.ServiceTypeNodePort),
107109
"The type of service to create for the cluster registry. Options: 'LoadBalancer', 'NodePort'.")
108110
}
@@ -299,7 +301,7 @@ func createServiceAccount(clientset client.Interface,
299301
ObjectMeta: metav1.ObjectMeta{
300302
Name: serviceAccountName,
301303
Namespace: namespace,
302-
Labels: util.ComponentLabel,
304+
Labels: common.ComponentLabel,
303305
},
304306
}
305307

@@ -324,7 +326,7 @@ func createClusterRole(clientset client.Interface,
324326
cr := &rbacv1.ClusterRole{
325327
ObjectMeta: metav1.ObjectMeta{
326328
Name: clusterRoleName,
327-
Labels: util.ComponentLabel,
329+
Labels: common.ComponentLabel,
328330
},
329331
Rules: []rbacv1.PolicyRule{rule},
330332
}
@@ -345,7 +347,7 @@ func createClusterRoleBindings(clientset client.Interface,
345347
// cluster role.
346348
crb, err := createClusterRoleBindingObject(clientset, apiServerCRBName,
347349
rbacv1.ServiceAccountKind, serviceAccountName, namespace, rbacv1.GroupName,
348-
"ClusterRole", clusterRoleName, util.ComponentLabel, dryRun)
350+
"ClusterRole", clusterRoleName, common.ComponentLabel, dryRun)
349351

350352
if err != nil {
351353
glog.V(4).Infof("Failed to create cluster role binding %v: %v", crb, err)
@@ -355,7 +357,7 @@ func createClusterRoleBindings(clientset client.Interface,
355357
// Create cluster role binding for the system:auth-delegator cluster role.
356358
crb, err = createClusterRoleBindingObject(clientset, authDelegatorCRBName,
357359
rbacv1.ServiceAccountKind, serviceAccountName, namespace, rbacv1.GroupName,
358-
"ClusterRole", "system:auth-delegator", util.ComponentLabel, dryRun)
360+
"ClusterRole", "system:auth-delegator", common.ComponentLabel, dryRun)
359361

360362
if err != nil {
361363
glog.V(4).Infof("Failed to create cluster role binding %v: %v", crb, err)
@@ -404,7 +406,7 @@ func createExtensionAPIServerAuthenticationRoleBinding(clientset client.Interfac
404406
rb := &rbacv1.RoleBinding{
405407
ObjectMeta: metav1.ObjectMeta{
406408
Name: name,
407-
Labels: util.ComponentLabel,
409+
Labels: common.ComponentLabel,
408410
},
409411
Subjects: []rbacv1.Subject{
410412
{
@@ -462,7 +464,7 @@ func createAPIServiceObject(clientset apiregclient.Interface,
462464
apiSvc := &apiregv1beta1.APIService{
463465
ObjectMeta: metav1.ObjectMeta{
464466
Name: apiServiceName,
465-
Labels: util.ComponentLabel,
467+
Labels: common.ComponentLabel,
466468
},
467469
Spec: apiregv1beta1.APIServiceSpec{
468470
Service: &apiregv1beta1.ServiceReference{

pkg/crinit/common/common.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package common contains code shared between the subcommands of crinit.
1718
package common
1819

1920
import (
@@ -63,7 +64,7 @@ var (
6364
)
6465

6566
type EntityKeyPairs struct {
66-
Ca *triple.KeyPair
67+
CA *triple.KeyPair
6768
Server *triple.KeyPair
6869
Admin *triple.KeyPair
6970
}
@@ -182,10 +183,10 @@ func GetClusterNodeIPs(clientset client.Interface) ([]string, error) {
182183
// CreateAPIServerCredentialsSecret helper to create secret object and return
183184
// the object.
184185
func CreateAPIServerCredentialsSecret(clientset client.Interface, namespace,
185-
credentialsName string, credentials Credentials, dryRun bool) (*v1.Secret, error) {
186+
credentialsName string, credentials *Credentials, dryRun bool) (*v1.Secret, error) {
186187
// Build the secret object with API server credentials.
187188
data := map[string][]byte{
188-
"ca.crt": certutil.EncodeCertPEM(credentials.CertEntKeyPairs.Ca.Cert),
189+
"ca.crt": certutil.EncodeCertPEM(credentials.CertEntKeyPairs.CA.Cert),
189190
"server.crt": certutil.EncodeCertPEM(credentials.CertEntKeyPairs.Server.Cert),
190191
"server.key": certutil.EncodePrivateKeyPEM(credentials.CertEntKeyPairs.Server.Key),
191192
}
@@ -251,7 +252,7 @@ etcdPVStorageClass string, dryRun bool) (*v1.PersistentVolumeClaim, error) {
251252
return clientset.CoreV1().PersistentVolumeClaims(namespace).Create(pvc)
252253
}
253254

254-
// createAPIServer helper to create the apiserver deployment object and
255+
// CreateAPIServer helper to create the apiserver deployment object and
255256
// return the object.
256257
func CreateAPIServer(clientset client.Interface, namespace, name, serverImage,
257258
etcdImage, advertiseAddress, credentialsName, serviceAccountName string, hasHTTPBasicAuthFile,

pkg/crinit/options/options.go

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package options contains implemention for SubcommandOptions.
1718
package options
1819

1920
import (
@@ -42,7 +43,7 @@ const (
4243
APIServerNameSuffix = "apiserver"
4344
CredentialSuffix = "credentials"
4445

45-
apiserverAdvertiseAddressFlag = "api-server-advertise-address"
46+
APIServerAdvertiseAddressFlag = "api-server-advertise-address"
4647
APIServerServiceTypeFlag = "api-server-service-type"
4748
apiserverPortFlag = "api-server-port"
4849
)
@@ -65,12 +66,12 @@ type SubcommandOptions struct {
6566
EtcdPVStorageClass string
6667
EtcdPersistentStorage bool
6768
DryRun bool
68-
ApiServerOverridesString string
69-
ApiServerOverrides map[string]string
70-
ApiServerServiceType v1.ServiceType
71-
ApiServerAdvertiseAddress string
72-
ApiServerNodePortPort int32
73-
ApiServerNodePortPortPtr *int32
69+
APIServerOverridesString string
70+
APIServerOverrides map[string]string
71+
APIServerServiceType v1.ServiceType
72+
APIServerAdvertiseAddress string
73+
APIServerNodePortPort int32
74+
APIServerNodePortPortPtr *int32
7475
}
7576

7677
// BindCommon adds the common options that are shared by different
@@ -95,11 +96,11 @@ func (o *SubcommandOptions) BindCommon(flags *pflag.FlagSet, defaultServerImage,
9596
"Use a persistent volume for etcd. Defaults to 'true'.")
9697
flags.BoolVar(&o.DryRun, "dry-run", false,
9798
"Run the command in dry-run mode, without making any server requests.")
98-
flags.StringVar(&o.ApiServerOverridesString, "apiserver-arg-overrides", "",
99+
flags.StringVar(&o.APIServerOverridesString, "apiserver-arg-overrides", "",
99100
"Comma-separated list of cluster registry API server arguments to override, e.g., \"--arg1=value1,--arg2=value2...\"")
100-
flags.StringVar(&o.ApiServerAdvertiseAddress, apiserverAdvertiseAddressFlag, "",
101+
flags.StringVar(&o.APIServerAdvertiseAddress, APIServerAdvertiseAddressFlag, "",
101102
"Preferred address at which to advertise the cluster registry API server NodePort service. Valid only if '"+APIServerServiceTypeFlag+"=NodePort'.")
102-
flags.Int32Var(&o.ApiServerNodePortPort, apiserverPortFlag, 0,
103+
flags.Int32Var(&o.APIServerNodePortPort, apiserverPortFlag, 0,
103104
"Preferred port to use for the cluster registry API server NodePort service. Set to 0 to randomly assign a port. Valid only if '"+APIServerServiceTypeFlag+"=NodePort'.")
104105
}
105106

@@ -118,36 +119,36 @@ func (o *SubcommandOptions) ValidateCommonOptions() error {
118119
serverName = fmt.Sprintf("%s-%s", o.Name, APIServerNameSuffix)
119120
serverCredName = fmt.Sprintf("%s-%s", serverName, CredentialSuffix)
120121

121-
if o.ApiServerServiceType != v1.ServiceTypeLoadBalancer &&
122-
o.ApiServerServiceType != v1.ServiceTypeNodePort {
122+
if o.APIServerServiceType != v1.ServiceTypeLoadBalancer &&
123+
o.APIServerServiceType != v1.ServiceTypeNodePort {
123124
return fmt.Errorf("invalid %s: %s, should be either %s or %s",
124-
APIServerServiceTypeFlag, o.ApiServerServiceType,
125+
APIServerServiceTypeFlag, o.APIServerServiceType,
125126
v1.ServiceTypeLoadBalancer, v1.ServiceTypeNodePort)
126127
}
127128

128-
if o.ApiServerAdvertiseAddress != "" {
129-
ip := net.ParseIP(o.ApiServerAdvertiseAddress)
129+
if o.APIServerAdvertiseAddress != "" {
130+
ip := net.ParseIP(o.APIServerAdvertiseAddress)
130131
if ip == nil {
131132
return fmt.Errorf("invalid %s: %s, should be a valid ip address",
132-
apiserverAdvertiseAddressFlag, o.ApiServerAdvertiseAddress)
133+
APIServerAdvertiseAddressFlag, o.APIServerAdvertiseAddress)
133134
}
134-
if o.ApiServerServiceType != v1.ServiceTypeNodePort {
135+
if o.APIServerServiceType != v1.ServiceTypeNodePort {
135136
return fmt.Errorf("%s should be passed only with '%s=NodePort'",
136-
apiserverAdvertiseAddressFlag, APIServerServiceTypeFlag)
137+
APIServerAdvertiseAddressFlag, APIServerServiceTypeFlag)
137138
}
138139
}
139140

140-
if o.ApiServerNodePortPort != 0 {
141-
if o.ApiServerServiceType != v1.ServiceTypeNodePort {
141+
if o.APIServerNodePortPort != 0 {
142+
if o.APIServerServiceType != v1.ServiceTypeNodePort {
142143
return fmt.Errorf("%s should be passed only with '%s=NodePort'",
143144
apiserverPortFlag, APIServerServiceTypeFlag)
144145
}
145-
o.ApiServerNodePortPortPtr = &o.ApiServerNodePortPort
146+
o.APIServerNodePortPortPtr = &o.APIServerNodePortPort
146147
} else {
147-
o.ApiServerNodePortPortPtr = nil
148+
o.APIServerNodePortPortPtr = nil
148149
}
149150

150-
if o.ApiServerNodePortPort < 0 || o.ApiServerNodePortPort > 65535 {
151+
if o.APIServerNodePortPort < 0 || o.APIServerNodePortPort > 65535 {
151152
return fmt.Errorf("Please provide a valid port number for %s", apiserverPortFlag)
152153
}
153154

@@ -156,12 +157,12 @@ func (o *SubcommandOptions) ValidateCommonOptions() error {
156157

157158
// marshalOptions marshals options if necessary.
158159
func (o *SubcommandOptions) MarshalOptions() error {
159-
if o.ApiServerOverridesString == "" {
160+
if o.APIServerOverridesString == "" {
160161
return nil
161162
}
162163

163164
argsMap := make(map[string]string)
164-
overrideArgs := strings.Split(o.ApiServerOverridesString, ",")
165+
overrideArgs := strings.Split(o.APIServerOverridesString, ",")
165166
for _, overrideArg := range overrideArgs {
166167
splitArg := strings.SplitN(overrideArg, "=", 2)
167168
if len(splitArg) != 2 {
@@ -175,7 +176,7 @@ func (o *SubcommandOptions) MarshalOptions() error {
175176
argsMap[key] = val
176177
}
177178

178-
o.ApiServerOverrides = argsMap
179+
o.APIServerOverrides = argsMap
179180

180181
return nil
181182
}
@@ -208,8 +209,8 @@ func (o *SubcommandOptions) CreateService(cmdOut io.Writer,
208209
glog.V(4).Info("Creating cluster registry API server service")
209210

210211
svc, ips, hostnames, err := common.CreateService(cmdOut, clientset,
211-
o.ClusterRegistryNamespace, o.Name, o.ApiServerAdvertiseAddress,
212-
o.ApiServerNodePortPortPtr, o.ApiServerServiceType, o.DryRun)
212+
o.ClusterRegistryNamespace, o.Name, o.APIServerAdvertiseAddress,
213+
o.APIServerNodePortPortPtr, o.APIServerServiceType, o.DryRun)
213214

214215
if err != nil {
215216
return nil, nil, nil, err
@@ -245,7 +246,7 @@ func (o *SubcommandOptions) GenerateCredentials(cmdOut io.Writer, svcName string
245246
// CreateAPIServerCredentialsSecret creates the secret containing the
246247
// apiserver credentials passed in.
247248
func (o *SubcommandOptions) CreateAPIServerCredentialsSecret(clientset client.Interface,
248-
credentials common.Credentials) error {
249+
credentials *common.Credentials) error {
249250

250251
_, err := common.CreateAPIServerCredentialsSecret(clientset,
251252
o.ClusterRegistryNamespace, serverCredName, credentials, o.DryRun)
@@ -285,8 +286,8 @@ func (o *SubcommandOptions) CreateAPIServer(cmdOut io.Writer, clientset client.I
285286
pvc *v1.PersistentVolumeClaim, serviceAccountName string) error {
286287
// Since only one IP address can be specified as advertise address,
287288
// we arbitrarily pick the first available IP address.
288-
// Pick user provided apiserverAdvertiseAddress over other available IP addresses.
289-
advertiseAddress := o.ApiServerAdvertiseAddress
289+
// Pick user provided APIServerAdvertiseAddress over other available IP addresses.
290+
advertiseAddress := o.APIServerAdvertiseAddress
290291
if advertiseAddress == "" && len(ips) > 0 {
291292
advertiseAddress = ips[0]
292293
}
@@ -297,7 +298,7 @@ func (o *SubcommandOptions) CreateAPIServer(cmdOut io.Writer, clientset client.I
297298
_, err := common.CreateAPIServer(clientset, o.ClusterRegistryNamespace,
298299
serverName, o.ServerImage, o.EtcdImage, advertiseAddress, serverCredName,
299300
serviceAccountName, apiServerEnableHTTPBasicAuth, apiServerEnableTokenAuth,
300-
o.ApiServerOverrides, pvc, aggregated, o.DryRun)
301+
o.APIServerOverrides, pvc, aggregated, o.DryRun)
301302

302303
if err != nil {
303304
glog.V(4).Infof("Failed to create API server: %v", err)
@@ -331,7 +332,7 @@ func (o *SubcommandOptions) UpdateKubeconfig(cmdOut io.Writer,
331332

332333
// If the service is nodeport, need to append the port to endpoint as it is
333334
// non-standard port.
334-
if o.ApiServerServiceType == v1.ServiceTypeNodePort {
335+
if o.APIServerServiceType == v1.ServiceTypeNodePort {
335336
endpoint = endpoint + ":" + strconv.Itoa(int(svc.Spec.Ports[0].NodePort))
336337
}
337338

pkg/crinit/standalone/standalone.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
client "k8s.io/client-go/kubernetes"
2727
"k8s.io/client-go/tools/clientcmd"
2828
"k8s.io/cluster-registry/pkg/crinit/util"
29+
"k8s.io/cluster-registry/pkg/crinit/options"
2930

3031
"github.com/golang/glog"
3132
"github.com/spf13/cobra"
@@ -48,14 +49,14 @@ var (
4849
)
4950

5051
type standaloneClusterRegistryOptions struct {
51-
util.SubcommandOptions
52+
options.SubcommandOptions
5253
apiServerServiceTypeString string
5354
apiServerEnableHTTPBasicAuth bool
5455
apiServerEnableTokenAuth bool
5556
}
5657

5758
func (o *standaloneClusterRegistryOptions) Bind(flags *pflag.FlagSet) {
58-
flags.StringVar(&o.apiServerServiceTypeString, util.APIServerServiceTypeFlag,
59+
flags.StringVar(&o.apiServerServiceTypeString, options.APIServerServiceTypeFlag,
5960
string(v1.ServiceTypeLoadBalancer),
6061
"The type of service to create for the cluster registry. Options: 'LoadBalancer', 'NodePort'.")
6162
flags.BoolVar(&o.apiServerEnableHTTPBasicAuth, "apiserver-enable-basic-auth", false,

0 commit comments

Comments
 (0)