Skip to content

Commit e49bc30

Browse files
authored
🐛 Clean code & prep for CI enable (#7)
* add bin dir to git * lint and prow fix
1 parent 84e69bf commit e49bc30

File tree

8 files changed

+30
-18
lines changed

8 files changed

+30
-18
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
.vscode
44
vendor
55
hack/tools/*
6-
bin/*
6+
bin/gcp

.prow.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
presubmits:
2-
- name: pull-kcp-verify
2+
- name: pull-gcp-verify
33
always_run: true
44
decorate: true
5-
clone_uri: "https://github.com/kcp-dev/kcp"
5+
clone_uri: "https://github.com/kcp-dev/generic-controlplane"
66
labels:
77
preset-goproxy: "true"
88
spec:
@@ -11,8 +11,6 @@ presubmits:
1111
command:
1212
- make
1313
- verify-boilerplate
14-
- verify-modules
15-
- verify-k8s-deps
1614
- verify-imports
1715
resources:
1816
requests:
@@ -22,7 +20,7 @@ presubmits:
2220
- name: pull-gco-lint
2321
always_run: true
2422
decorate: true
25-
clone_uri: "https://github.com/kcp-dev/kcp"
23+
clone_uri: "https://github.com/kcp-dev/generic-controlplane"
2624
labels:
2725
preset-goproxy: "true"
2826
spec:
@@ -49,7 +47,7 @@ presubmits:
4947
- hack/build-image.sh
5048
env:
5149
- name: DRY_RUN
52-
value: '1'
50+
value: "1"
5351
# docker-in-docker needs privileged mode
5452
securityContext:
5553
privileged: true
@@ -72,9 +70,8 @@ presubmits:
7270
- test
7371
env:
7472
- name: USE_GOTESTSUM
75-
value: '1'
73+
value: "1"
7674
resources:
7775
requests:
7876
memory: 4Gi
7977
cpu: 2
80-

bin/.gitkeep

Whitespace-only changes.

server/admission/plugins.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var AllOrderedPlugins = []string{
4545
autoprovision.PluginName, // NamespaceAutoProvision
4646
lifecycle.PluginName, // NamespaceLifecycle
4747
exists.PluginName, // NamespaceExists
48-
//limitranger.PluginName, // LimitRanger
48+
// limitranger.PluginName, // LimitRanger
4949
serviceaccount.PluginName, // ServiceAccount
5050
eventratelimit.PluginName, // EventRateLimit
5151
gc.PluginName, // OwnerReferencesPermissionEnforcement
@@ -70,7 +70,7 @@ func RegisterAllAdmissionPlugins(plugins *admission.Plugins) {
7070
autoprovision.Register(plugins)
7171
lifecycle.Register(plugins)
7272
exists.Register(plugins)
73-
//limitranger.Register(plugins)
73+
// limitranger.Register(plugins)
7474
serviceaccount.Register(plugins)
7575
eventratelimit.Register(plugins)
7676
gc.Register(plugins)
@@ -89,7 +89,7 @@ func RegisterAllAdmissionPlugins(plugins *admission.Plugins) {
8989
func DefaultOffAdmissionPlugins() sets.Set[string] {
9090
defaultOnPlugins := sets.New(
9191
lifecycle.PluginName, // NamespaceLifecycle
92-
//limitranger.PluginName, // LimitRanger
92+
// limitranger.PluginName, // LimitRanger
9393
serviceaccount.PluginName, // ServiceAccount
9494
defaulttolerationseconds.PluginName, // DefaultTolerationSeconds
9595
mutatingwebhook.PluginName, // MutatingAdmissionWebhook

server/cmd/options/authentication.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,24 @@ const (
4141
gcpUserUserName = "user"
4242
)
4343

44+
// AdminAuthentication holds the configuration for the admin authentication in standalone mode.
4445
type AdminAuthentication struct {
4546
KubeConfigPath string
4647

4748
// TODO: move into Secret in-cluster, maybe by using an "in-cluster" string as value
4849
ShardAdminTokenHashFilePath string
4950
}
5051

52+
// NewAdminAuthentication returns a new AdminAuthentication for the given root directory
53+
// where the kubeconfig and the token hash file should be written.
5154
func NewAdminAuthentication(rootDir string) *AdminAuthentication {
5255
return &AdminAuthentication{
5356
KubeConfigPath: filepath.Join(rootDir, "admin.kubeconfig"),
5457
ShardAdminTokenHashFilePath: filepath.Join(rootDir, ".admin-token-store"),
5558
}
5659
}
5760

61+
// Validate validates the admin authentication configuration.
5862
func (s *AdminAuthentication) Validate() []error {
5963
if s == nil {
6064
return nil
@@ -69,6 +73,7 @@ func (s *AdminAuthentication) Validate() []error {
6973
return errs
7074
}
7175

76+
// AddFlags adds the flags for the admin authentication to the given FlagSet.
7277
func (s *AdminAuthentication) AddFlags(fs *pflag.FlagSet) {
7378
if s == nil {
7479
return
@@ -118,6 +123,7 @@ func (s *AdminAuthentication) ApplyTo(config *genericapiserver.Config) (volatile
118123
return volatileGcpAdminToken, volatileUserToken, nil
119124
}
120125

126+
// WriteKubeConfig writes the kubeconfig to the configured path.
121127
func (s *AdminAuthentication) WriteKubeConfig(config genericapiserver.CompletedConfig, gcpAdminToken, userToken string) error {
122128
externalCACert, _ := config.SecureServing.Cert.CurrentCertKeyContent()
123129
externalKubeConfigHost := fmt.Sprintf("https://%s", config.ExternalAddress)

server/cmd/options/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
generatedopenapi "k8s.io/kubernetes/pkg/generated/openapi"
3131
)
3232

33+
// Config holds the configuration for the generic controlplane server.
3334
type Config struct {
3435
Options CompletedOptions
3536

@@ -41,6 +42,7 @@ type Config struct {
4142
ExtraConfig
4243
}
4344

45+
// ExtraConfig holds the extra configuration for the generic controlplane server.
4446
type ExtraConfig struct {
4547
// authentication
4648
GcpAdminToken, UserToken string
@@ -58,11 +60,13 @@ type completedConfig struct {
5860
ExtraConfig
5961
}
6062

63+
// CompletedConfig holds the completed configuration for the generic controlplane server.
6164
type CompletedConfig struct {
6265
// Embed a private pointer that cannot be instantiated outside of this package.
6366
*completedConfig
6467
}
6568

69+
// Complete fills in any fields not set that are required to have valid data.
6670
func (c *Config) Complete() (CompletedConfig, error) {
6771
return CompletedConfig{&completedConfig{
6872
Options: c.Options,

server/cmd/options/options.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
gcpadmission "github.com/kcp-dev/generic-controlplane/server/admission"
3737
)
3838

39+
// Options holds the configuration for the generic controlplane server.
3940
type Options struct {
4041
GenericControlPlane controlplaneapiserveroptions.Options
4142
EmbeddedEtcd etcdoptions.Options
@@ -45,6 +46,7 @@ type Options struct {
4546
Extra ExtraOptions
4647
}
4748

49+
// ExtraOptions holds the extra configuration for the generic controlplane server.
4850
type ExtraOptions struct {
4951
RootDir string
5052
}
@@ -58,6 +60,7 @@ type completedOptions struct {
5860
Extra ExtraOptions
5961
}
6062

63+
// CompletedOptions holds the completed configuration for the generic controlplane server.
6164
type CompletedOptions struct {
6265
*completedOptions
6366
}
@@ -99,6 +102,7 @@ func NewOptions(rootDir string) *Options {
99102
return o
100103
}
101104

105+
// AddFlags adds flags for a specific APIServer to the specified FlagSet.
102106
func (o *Options) AddFlags(fss *cliflag.NamedFlagSets) {
103107
o.GenericControlPlane.AddFlags(fss)
104108

@@ -112,6 +116,7 @@ func (o *Options) AddFlags(fss *cliflag.NamedFlagSets) {
112116
// Placeholders for future flags.
113117
}
114118

119+
// Complete fills in any fields not set that are required to have valid data.
115120
func (o *Options) Complete() (*CompletedOptions, error) {
116121
if servers := o.GenericControlPlane.Etcd.StorageConfig.Transport.ServerList; len(servers) == 1 && servers[0] == "embedded" {
117122
klog.Background().Info("enabling embedded etcd server")
@@ -149,7 +154,6 @@ func (o *Options) Complete() (*CompletedOptions, error) {
149154
}
150155

151156
// override set of admission plugins
152-
//spew.Dump(o.GenericControlPlane.Admission.GenericAdmission.Plugins)
153157
gcpadmission.RegisterAllAdmissionPlugins(o.GenericControlPlane.Admission.GenericAdmission.Plugins)
154158
o.GenericControlPlane.Admission.GenericAdmission.DisablePlugins = sets.List[string](gcpadmission.DefaultOffAdmissionPlugins())
155159
o.GenericControlPlane.Admission.GenericAdmission.RecommendedPluginOrder = gcpadmission.AllOrderedPlugins
@@ -197,6 +201,7 @@ func (o *Options) Complete() (*CompletedOptions, error) {
197201
}, nil
198202
}
199203

204+
// Validate validates the generic controlplane server options.
200205
func (o *CompletedOptions) Validate() []error {
201206
var errs []error
202207

server/cmd/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828
"github.com/spf13/cobra"
2929

3030
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
31-
utilerrors "k8s.io/apimachinery/pkg/util/errors"
31+
kerrors "k8s.io/apimachinery/pkg/util/errors"
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
33-
_ "k8s.io/apiserver/pkg/admission"
33+
_ "k8s.io/apiserver/pkg/admission" // for admission plugins
3434
genericapifilters "k8s.io/apiserver/pkg/endpoints/filters"
3535
genericapiserver "k8s.io/apiserver/pkg/server"
3636
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -41,14 +41,14 @@ import (
4141
"k8s.io/component-base/cli/globalflag"
4242
"k8s.io/component-base/logs"
4343
logsapi "k8s.io/component-base/logs/api/v1"
44-
_ "k8s.io/component-base/metrics/prometheus/workqueue"
44+
_ "k8s.io/component-base/metrics/prometheus/workqueue" // for workqueue metrics
4545
"k8s.io/component-base/term"
4646
"k8s.io/component-base/version"
4747
"k8s.io/component-base/version/verflag"
4848
"k8s.io/klog/v2"
4949
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
5050
controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver"
51-
_ "k8s.io/kubernetes/pkg/features"
51+
_ "k8s.io/kubernetes/pkg/features" // add the kubernetes feature gates
5252

5353
options "github.com/kcp-dev/generic-controlplane/server/cmd/options"
5454
// add the kubernetes feature gates
@@ -108,7 +108,7 @@ APIs.`,
108108
}
109109

110110
if errs := completedOptions.Validate(); len(errs) != 0 {
111-
return utilerrors.NewAggregate(errs)
111+
return kerrors.NewAggregate(errs)
112112
}
113113

114114
// add feature enablement metrics

0 commit comments

Comments
 (0)