Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap Configuration #302

Merged
merged 8 commits into from
Apr 8, 2024
Merged

Bootstrap Configuration #302

merged 8 commits into from
Apr 8, 2024

Conversation

neoaggelos
Copy link
Contributor

@neoaggelos neoaggelos commented Apr 5, 2024

Summary

Make sure we can set all fields with BootstrapConfig when starting the cluster. Re-use the UserFacingClusterConfig, so that all fields from k8s set are available on bootstrap.

Changes

  • Update apiv1.BootstrapConfig
  • Add unit tests for apiv1.BootstrapConfig <-> types.ClusterConfig
  • Only set defaults on the server side when bootstrapping the cluster
  • Use yaml.UnmarshalStrict for parsing the config file, such that unknown keys are not silently ignored.
  • Test coverage

@neoaggelos neoaggelos requested a review from a team as a code owner April 5, 2024 12:45
Copy link
Contributor

@eaudetcobello eaudetcobello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job

src/k8s/cmd/k8s/k8s_bootstrap.go Show resolved Hide resolved
src/k8s/cmd/k8s/k8s_bootstrap.go Outdated Show resolved Hide resolved
Copy link
Contributor

@addyess addyess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More comments than approval/disapproval

Comment on lines 20 to 24
DatastoreType *string `json:"datastore-type,omitempty" yaml:"datastore-type,omitempty"`
DatastoreURL *string `json:"datastore-url,omitempty" yaml:"datastore-url,omitempty"`
DatastoreCACert *string `json:"datastore-ca-crt,omitempty" yaml:"datastore-ca-crt,omitempty"`
DatastoreClientCert *string `json:"datastore-client-crt,omitempty" yaml:"datastore-client-crt,omitempty"`
DatastoreClientKey *string `json:"datastore-client-key,omitempty" yaml:"datastore-client-key,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DatastoreType seems superfluous. Help me know why its there?

if we're using a socket for k8sdqlite, isn't that socket file just a DatastoreURL?

secondarily -- DatastoreURL should really be a []string because i understand that the args are a comma joined set of URLs. right?

Copy link
Member

@mateoflorido mateoflorido Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addyess We could use external datastore. If that's the case, we bootstrap the node with datastore-type: external

Copy link
Contributor

@addyess addyess Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateoflorido no i get that completely. I just think that if you override the datastore url, you're very obviously using an "external" datastore. from the kube-apiserver, it just wants to know the following:

etcd-servers
etcd-keyfile
etcd-certfile
etcd-cafile

it doesn't have a special name for the type. This bootstrap config should represent only those things. The "type" is a made up thing internally to this app but is unnecessary.

the default should be etcd-servers = DatastoreURL = unix:///var/snap..../k8sdqlite.socket
and if someone wants it to be something else like a URL -- cool so be it. Why is it necessary to drag this extra stringly typed field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addyess The DatastoreType is external for etcd for example. We've got some logic based on the value of this type when we grab the cluster config from the bootstrap config. We're also using it to print our k8s status. In theory we could check if the DatastoreURL is set and that would mean we are dealing with an external datastore but that might make those switch statements quite ugly.

src/k8s/api/v1/bootstrap_config.go Show resolved Hide resolved
src/k8s/cmd/k8s/k8s_bootstrap.go Show resolved Hide resolved
src/k8s/cmd/k8s/k8s_bootstrap.go Outdated Show resolved Hide resolved
src/k8s/cmd/k8s/k8s_bootstrap.go Show resolved Hide resolved
Comment on lines 23 to 39
switch b.GetDatastoreType() {
case "", "k8s-dqlite":
config.Datastore = Datastore{
Type: vals.Pointer("k8s-dqlite"),
K8sDqlitePort: vals.Pointer(b.K8sDqlitePort),
K8sDqlitePort: b.K8sDqlitePort,
}
case "external":
config.Datastore = Datastore{
Type: vals.Pointer("external"),
ExternalURL: vals.Pointer(b.DatastoreURL),
ExternalCACert: vals.Pointer(b.DatastoreCACert),
ExternalClientCert: vals.Pointer(b.DatastoreClientCert),
ExternalClientKey: vals.Pointer(b.DatastoreClientKey),
ExternalURL: b.DatastoreURL,
ExternalCACert: b.DatastoreCACert,
ExternalClientCert: b.DatastoreClientCert,
ExternalClientKey: b.DatastoreClientKey,
}
default:
return ClusterConfig{}, fmt.Errorf("unknown datastore type specified in bootstrap config %q", b.GetDatastoreType())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep getting hung up here. why'd we invent our own switch for datastore type baked into the config. Feels mostly like a cli thing. Either there is an external datastore or there isn't. If there's no user configured DatastoreURL -- then we should default to the k8s-dqlite socket.

Copy link
Contributor

@bschimke95 bschimke95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only a minor comment - feel free to ignore.

}
case "external":
if len(b.DatastoreServers) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we introduce a BootstrapConfig.validate method that checks that (and other validation, if any)?

Copy link
Contributor

github-actions bot commented Apr 8, 2024

Package Line Rate
github.com/canonical/k8s/api/v1 43%
github.com/canonical/k8s/cmd/k8s 29%
github.com/canonical/k8s/cmd/util 14%
github.com/canonical/k8s/pkg/client/dqlite 44%
github.com/canonical/k8s/pkg/component 10%
github.com/canonical/k8s/pkg/k8sd/controllers 63%
github.com/canonical/k8s/pkg/k8sd/database 48%
github.com/canonical/k8s/pkg/k8sd/pki 53%
github.com/canonical/k8s/pkg/k8sd/setup 75%
github.com/canonical/k8s/pkg/k8sd/types 82%
github.com/canonical/k8s/pkg/proxy 6%
github.com/canonical/k8s/pkg/snap 15%
github.com/canonical/k8s/pkg/snap/util 90%
github.com/canonical/k8s/pkg/utils 41%
github.com/canonical/k8s/pkg/utils/control 61%
github.com/canonical/k8s/pkg/utils/errors 100%
github.com/canonical/k8s/pkg/utils/k8s 71%
Summary 41% (2010 / 4850)

@neoaggelos neoaggelos merged commit 6178860 into main Apr 8, 2024
15 checks passed
@neoaggelos neoaggelos deleted the KU-502/bootstrap-config branch April 8, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants