Skip to content

Commit 04742b9

Browse files
committed
feat: import fixes/updates from kubeadm bootstrap provider
This adds new conditions, and some small features, cleaning up failure conditions. Some changes: * tests no longer set up owner refs, they should be set by core CAPI controllers * set correctly `BootstrapRef` * TalosConfig controller no longer fails when requeueing is handled by watches * more tests for conditions With conditions enabled there should be no longer required to look into the controller logs to see why reconciliation failed. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
1 parent 548b7fb commit 04742b9

15 files changed

+401
-87
lines changed

.drone.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: default
55

66
services:
77
- name: docker
8-
image: docker:20.10-dind
8+
image: ghcr.io/smira/docker:20.10-dind-hacked
99
entrypoint: [dockerd]
1010
privileged: true
1111
volumes:
@@ -53,6 +53,7 @@ steps:
5353
INTEGRATION_SKIP_CLEANUP: 1 # make things a bit faster
5454
commands:
5555
- make env-up
56+
- make release-manifests
5657
- make test
5758
when:
5859
event:
@@ -74,6 +75,10 @@ steps:
7475
environment:
7576
CODECOV_TOKEN:
7677
from_secret: CODECOV_TOKEN
78+
when:
79+
event:
80+
include:
81+
- pull_request
7782
volumes:
7883
- name: docker-socket
7984
path: /var/run
@@ -176,6 +181,6 @@ depends_on:
176181

177182
---
178183
kind: signature
179-
hmac: a7d3d09b2ec221337f14cde8f5f2a872a4c3500df09b7f27e6a169a4eb35944b
184+
hmac: 405eea502f51dfc9368f81971ca97c96ac99f5fff6ddc1afa613894e80dd67c2
180185

181186
...

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ COPY --from=generate-build /src/api /api
5555
FROM build AS integration-test-build
5656
ENV CGO_ENABLED 1
5757
ARG TALOS_VERSION
58-
ARG GO_LDFLAGS="-linkmode=external -extldflags '-static' -X github.com/talos-systems/cluster-api-bootstrap-provider-talos/internal/integration.TalosVersion=${TALOS_VERSION}"
58+
ARG TAG
59+
ARG ARTIFACTS
60+
ARG PKG=github.com/talos-systems/cluster-api-bootstrap-provider-talos/internal/integration
61+
ARG GO_LDFLAGS="-linkmode=external -extldflags '-static' -X ${PKG}.TalosVersion=${TALOS_VERSION} -X ${PKG}.Artifacts=${ARTIFACTS} -X ${PKG}.Tag=${TAG}"
5962
RUN --mount=type=cache,target=/.cache go test -race -ldflags "${GO_LDFLAGS}" -coverpkg=./... -v -c ./internal/integration
6063

6164
FROM scratch AS integration-test
@@ -74,7 +77,7 @@ RUN cd config/manager \
7477
&& kustomize build config/default > /bootstrap-components.yaml \
7578
&& cp config/metadata/metadata.yaml /metadata.yaml
7679

77-
FROM scratch AS release
80+
FROM scratch AS release-manifests
7881
ARG TAG
7982
COPY --from=release-build /bootstrap-components.yaml /bootstrap-talos/${TAG}/bootstrap-components.yaml
8083
COPY --from=release-build /metadata.yaml /bootstrap-talos/${TAG}/metadata.yaml

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ COMMON_ARGS += --build-arg=TOOLS=$(TOOLS)
3131
COMMON_ARGS += --build-arg=CONTROLLER_GEN_VERSION=$(CONTROLLER_GEN_VERSION)
3232
COMMON_ARGS += --build-arg=CONVERSION_GEN_VERSION=$(CONVERSION_GEN_VERSION)
3333
COMMON_ARGS += --build-arg=TALOS_VERSION=$(TALOS_VERSION)
34+
COMMON_ARGS += --build-arg=ARTIFACTS=$(ARTIFACTS)
3435

3536
all: manifests container
3637

@@ -91,10 +92,13 @@ release-notes: ## Create the release notes.
9192
@mkdir -p $(ARTIFACTS)
9293
ARTIFACTS=$(ARTIFACTS) ./hack/release.sh $@ $(ARTIFACTS)/RELEASE_NOTES.md $(TAG)
9394

94-
.PHONY: release
95-
release: manifests container release-notes ## Create the release YAML. The build result will be ouput to the specified local destination.
95+
.PHONY: release-manifests
96+
release-manifests:
9697
@$(MAKE) local-$@ DEST=./$(ARTIFACTS) PLATFORM=linux/amd64
9798

99+
.PHONY: release
100+
release: manifests container release-notes release-manifests ## Create the release YAML. The build result will be ouput to the specified local destination.
101+
98102
.PHONY: deploy
99103
deploy: manifests ## Deploy to a cluster. This is for testing purposes only.
100104
kubectl apply -k config/default

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
## Intro
44

5-
The Cluster API Bootstrap Provider Talos (CABPT) is a project by [Talos Systems](https://www.talos-systems.com/) that provides a [Cluster API](https://github.com/kubernetes-sigs/cluster-api)(CAPI) bootstrap provider for use in deploying Talos-based Kubernetes nodes across any environment.
5+
The Cluster API Bootstrap Provider Talos (CABPT) is a project by [Sidero Labs](https://www.siderolabs.com/) that provides a [Cluster API](https://github.com/kubernetes-sigs/cluster-api)(CAPI) bootstrap provider for use in deploying Talos-based Kubernetes nodes across any environment.
66
Given some basic info, this provider will generate bootstrap configurations for a given machine and reconcile the necessary custom resources for CAPI to pick up the generated data.
77

88
## Corequisites
99

1010
There are a few corequisites and assumptions that go into using this project:
1111

1212
- [Cluster API](https://github.com/kubernetes-sigs/cluster-api)
13-
- [Cluster API Provider Metal](https://github.com/talos-systems/cluster-api-provider-metal) (optional)
1413

1514
## Building and Installing
1615

@@ -24,14 +23,14 @@ You will need at least the upstream CAPI components and an infrastructure provid
2423

2524
## Usage
2625

27-
CAPM supports a single API type, a TalosConfig.
26+
CABPT supports a single API type, a TalosConfig.
2827
You can create YAML definitions of a TalosConfig and `kubectl apply` them as part of a larger CAPI cluster deployment.
2928
Below is a bare-minimum example.
3029

3130
A basic config:
3231

3332
```yaml
34-
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2
33+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
3534
kind: TalosConfig
3635
metadata:
3736
name: talos-0
@@ -48,13 +47,13 @@ When creating a TalosConfig this way, you can then retrieve the talosconfig file
4847

4948
If you wish to do something more complex, we allow for the ability to supply an entire Talos config file to the resource.
5049
This can be done by setting the generateType to `none` and specifying a `data` field.
51-
This config file can be generated with `osctl config generate` and the edited to supply the various options you may desire.
50+
This config file can be generated with `talosctl config generate` and the edited to supply the various options you may desire.
5251
This full config is blindly copied from the `data` section of the spec and presented under `.status.bootstrapData` so that the upstream CAPI controllers can see it and make use.
5352

5453
An example of a more complex config:
5554

5655
```yaml
57-
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2
56+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
5857
kind: TalosConfig
5958
metadata:
6059
name: talos-0
@@ -72,5 +71,5 @@ spec:
7271
...
7372
```
7473

75-
Note that specifying the full config above removes the ability for our bootstrap provider to generate a talosconfig for use.
76-
As such, you should keep track of the talosconfig that's generated when running `osctl config generate`.
74+
Note that specifying the full config above removes the ability for our bootstrap provider to generate a machine configuration for use.
75+
As such, you should keep track of the machine configuration that's generated when running `talosctl config generate`.

api/v1alpha3/conditions.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package v1alpha3
6+
7+
import (
8+
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
9+
)
10+
11+
// Conditions and condition Reasons for the TalosConfig object
12+
13+
const (
14+
// DataSecretAvailableCondition documents the status of the bootstrap secret generation process.
15+
//
16+
// NOTE: When the DataSecret generation starts the process completes immediately and within the
17+
// same reconciliation, so the user will always see a transition from Wait to Generated without having
18+
// evidence that BootstrapSecret generation is started/in progress.
19+
DataSecretAvailableCondition capiv1.ConditionType = "DataSecretAvailable"
20+
21+
// WaitingForClusterInfrastructureReason (Severity=Info) document a bootstrap secret generation process
22+
// waiting for the cluster infrastructure to be ready.
23+
//
24+
// NOTE: Having the cluster infrastructure ready is a pre-condition for starting to create machines;
25+
// the TalosConfig controller ensure this pre-condition is satisfied.
26+
WaitingForClusterInfrastructureReason = "WaitingForClusterInfrastructure"
27+
28+
// DataSecretGenerationFailedReason (Severity=Warning) documents a TalosConfig controller detecting
29+
// an error while generating a data secret; those kind of errors are usually due to misconfigurations
30+
// and user intervention is required to get them fixed.
31+
DataSecretGenerationFailedReason = "DataSecretGenerationFailed"
32+
)

api/v1alpha3/talosconfig_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package v1alpha3
66

77
import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
910
)
1011

1112
const (
@@ -42,6 +43,14 @@ type TalosConfigStatus struct {
4243
// FailureMessage will be set on non-retryable errors
4344
// +optional
4445
FailureMessage string `json:"failureMessage,omitempty"`
46+
47+
// ObservedGeneration is the latest generation observed by the controller.
48+
// +optional
49+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
50+
51+
// Conditions defines current service state of the TalosConfig.
52+
// +optional
53+
Conditions capiv1.Conditions `json:"conditions,omitempty"`
4554
}
4655

4756
// +kubebuilder:object:root=true
@@ -58,6 +67,16 @@ type TalosConfig struct {
5867
Status TalosConfigStatus `json:"status,omitempty"`
5968
}
6069

70+
// GetConditions returns the set of conditions for this object.
71+
func (c *TalosConfig) GetConditions() capiv1.Conditions {
72+
return c.Status.Conditions
73+
}
74+
75+
// SetConditions sets the conditions on this object.
76+
func (c *TalosConfig) SetConditions(conditions capiv1.Conditions) {
77+
c.Status.Conditions = conditions
78+
}
79+
6180
// +kubebuilder:object:root=true
6281

6382
// TalosConfigList contains a list of TalosConfig

api/v1alpha3/zz_generated.deepcopy.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/bootstrap.cluster.x-k8s.io_talosconfigs.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,50 @@ spec:
118118
status:
119119
description: TalosConfigStatus defines the observed state of TalosConfig
120120
properties:
121+
conditions:
122+
description: Conditions defines current service state of the TalosConfig.
123+
items:
124+
description: Condition defines an observation of a Cluster API resource
125+
operational state.
126+
properties:
127+
lastTransitionTime:
128+
description: Last time the condition transitioned from one status
129+
to another. This should be when the underlying condition changed.
130+
If that is not known, then using the time when the API field
131+
changed is acceptable.
132+
format: date-time
133+
type: string
134+
message:
135+
description: A human readable message indicating details about
136+
the transition. This field may be empty.
137+
type: string
138+
reason:
139+
description: The reason for the condition's last transition
140+
in CamelCase. The specific API may choose whether or not this
141+
field is considered a guaranteed API. This field may not be
142+
empty.
143+
type: string
144+
severity:
145+
description: Severity provides an explicit classification of
146+
Reason code, so the users or machines can immediately understand
147+
the current situation and act accordingly. The Severity field
148+
MUST be set only when Status=False.
149+
type: string
150+
status:
151+
description: Status of the condition, one of True, False, Unknown.
152+
type: string
153+
type:
154+
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
155+
Many .condition.type values are consistent across resources
156+
like Available, but because arbitrary conditions can be useful
157+
(see .node.status.conditions), the ability to deconflict is
158+
important.
159+
type: string
160+
required:
161+
- status
162+
- type
163+
type: object
164+
type: array
121165
dataSecretName:
122166
description: DataSecretName is the name of the secret that stores
123167
the bootstrap data script.
@@ -128,6 +172,11 @@ spec:
128172
failureReason:
129173
description: FailureReason will be set on non-retryable errors
130174
type: string
175+
observedGeneration:
176+
description: ObservedGeneration is the latest generation observed
177+
by the controller.
178+
format: int64
179+
type: integer
131180
ready:
132181
description: Ready indicates the BootstrapData field is ready to be
133182
consumed

0 commit comments

Comments
 (0)