Skip to content

Commit 4e446e9

Browse files
authored
Drop default cluster profile, cleanup instance creation profiles and logic (#93)
--------- Signed-off-by: Angelos Kolaitis <neoaggelos@gmail.com>
1 parent 9d8cd78 commit 4e446e9

File tree

14 files changed

+85
-139
lines changed

14 files changed

+85
-139
lines changed

api/v1alpha2/condition_consts.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@ const (
2323
LoadBalancerProvisioningAbortedReason = "LoadBalancerProvisioningAbortedReason"
2424
)
2525

26-
const (
27-
// KubeadmProfileAvailableCondition documents the availability of the default kubeadm LXC profile.
28-
KubeadmProfileAvailableCondition = "KubeadmProfileAvailable"
29-
30-
// KubeadmProfileDisabledReason (Severity=Info) documents a LXCCluster controller detecting that the
31-
// LXCCluster spec requests that no default kubeam profile be created.
32-
KubeadmProfileDisabledReason = "KubeadmProfileDisabled"
33-
34-
// KubeadmProfileCreationFailedReason (Severity=Warning) documents a LXCCluster controller detecting
35-
// a retriable error while provisioning the default kubeadm LXC profile; those kind of errors are
36-
// usually transient and failed provisioning are automatically re-tried by the controller.'
37-
KubeadmProfileCreationFailedReason = "KubeadmProfileCreationFailed"
38-
39-
// KubeadmProfileCreationAbortedReason (Severity=Error) documents a LXCCluster controller detecting
40-
// an unrecoverable error while provisioning the default kubeadm LXC profile. This is usually because
41-
// of permission issues on the server, therefore requires user intervention.
42-
KubeadmProfileCreationAbortedReason = "KubeadmProfileCreationAborted"
43-
)
44-
4526
// Conditions and condition Reasons for the LXCMachine object.
4627

4728
const (

api/v1alpha2/lxccluster_types.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ type LXCClusterSpec struct {
5151
// +optional
5252
Unprivileged bool `json:"unprivileged"`
5353

54-
// Skip creation of the default kubeadm profile "cluster-api-$namespace-$name"
55-
// for LXCClusters.
54+
// Do not apply the default kubeadm profile on container instances.
5655
//
5756
// In this case, the cluster administrator is responsible to create the
5857
// profile manually and set the `.spec.template.spec.profiles` field of all
5958
// LXCMachineTemplate objects.
6059
//
61-
// This is useful in cases where a restricted project is used, which does not
62-
// allow privileged containers.
60+
// For more details on the default kubeadm profile that is applied, see
61+
// https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html
6362
//
6463
// +optional
6564
SkipDefaultKubeadmProfile bool `json:"skipDefaultKubeadmProfile"`
@@ -262,11 +261,6 @@ func (c *LXCCluster) GetLoadBalancerInstanceName() string {
262261
return fmt.Sprintf("%s-%s-lb", c.Name, hex.EncodeToString(hash[:3])[:5])
263262
}
264263

265-
// GetProfileName returns the profile name for the cluster LXC machines.
266-
func (c *LXCCluster) GetProfileName() string {
267-
return fmt.Sprintf("cluster-api-%s-%s", c.Namespace, c.Name)
268-
}
269-
270264
// +kubebuilder:object:root=true
271265

272266
// LXCClusterList contains a list of LXCCluster.

config/crd/bases/infrastructure.cluster.x-k8s.io_lxcclusters.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,14 @@ spec:
241241
type: object
242242
skipDefaultKubeadmProfile:
243243
description: |-
244-
Skip creation of the default kubeadm profile "cluster-api-$namespace-$name"
245-
for LXCClusters.
244+
Do not apply the default kubeadm profile on container instances.
246245
247246
In this case, the cluster administrator is responsible to create the
248247
profile manually and set the `.spec.template.spec.profiles` field of all
249248
LXCMachineTemplate objects.
250249
251-
This is useful in cases where a restricted project is used, which does not
252-
allow privileged containers.
250+
For more details on the default kubeadm profile that is applied, see
251+
https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html
253252
type: boolean
254253
unprivileged:
255254
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_lxcclustertemplates.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,14 @@ spec:
264264
type: object
265265
skipDefaultKubeadmProfile:
266266
description: |-
267-
Skip creation of the default kubeadm profile "cluster-api-$namespace-$name"
268-
for LXCClusters.
267+
Do not apply the default kubeadm profile on container instances.
269268
270269
In this case, the cluster administrator is responsible to create the
271270
profile manually and set the `.spec.template.spec.profiles` field of all
272271
LXCMachineTemplate objects.
273272
274-
This is useful in cases where a restricted project is used, which does not
275-
allow privileged containers.
273+
For more details on the default kubeadm profile that is applied, see
274+
https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html
276275
type: boolean
277276
unprivileged:
278277
description: |-

docs/book/src/reference/api/v1alpha2/api.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ bool
105105
</td>
106106
<td>
107107
<em>(Optional)</em>
108-
<p>Skip creation of the default kubeadm profile &ldquo;cluster-api-$namespace-$name&rdquo;
109-
for LXCClusters.</p>
108+
<p>Do not apply the default kubeadm profile on container instances.</p>
110109
<p>In this case, the cluster administrator is responsible to create the
111110
profile manually and set the <code>.spec.template.spec.profiles</code> field of all
112111
LXCMachineTemplate objects.</p>
113-
<p>This is useful in cases where a restricted project is used, which does not
114-
allow privileged containers.</p>
112+
<p>For more details on the default kubeadm profile that is applied, see
113+
<a href="https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html">https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html</a></p>
115114
</td>
116115
</tr>
117116
</table>
@@ -297,13 +296,12 @@ bool
297296
</td>
298297
<td>
299298
<em>(Optional)</em>
300-
<p>Skip creation of the default kubeadm profile &ldquo;cluster-api-$namespace-$name&rdquo;
301-
for LXCClusters.</p>
299+
<p>Do not apply the default kubeadm profile on container instances.</p>
302300
<p>In this case, the cluster administrator is responsible to create the
303301
profile manually and set the <code>.spec.template.spec.profiles</code> field of all
304302
LXCMachineTemplate objects.</p>
305-
<p>This is useful in cases where a restricted project is used, which does not
306-
allow privileged containers.</p>
303+
<p>For more details on the default kubeadm profile that is applied, see
304+
<a href="https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html">https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html</a></p>
307305
</td>
308306
</tr>
309307
</tbody>
@@ -532,13 +530,12 @@ bool
532530
</td>
533531
<td>
534532
<em>(Optional)</em>
535-
<p>Skip creation of the default kubeadm profile &ldquo;cluster-api-$namespace-$name&rdquo;
536-
for LXCClusters.</p>
533+
<p>Do not apply the default kubeadm profile on container instances.</p>
537534
<p>In this case, the cluster administrator is responsible to create the
538535
profile manually and set the <code>.spec.template.spec.profiles</code> field of all
539536
LXCMachineTemplate objects.</p>
540-
<p>This is useful in cases where a restricted project is used, which does not
541-
allow privileged containers.</p>
537+
<p>For more details on the default kubeadm profile that is applied, see
538+
<a href="https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html">https://lxc.github.io/cluster-api-provider-incus/reference/profile/kubeadm.html</a></p>
542539
</td>
543540
</tr>
544541
</table>

docs/book/src/reference/profile/kubeadm.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ When using unprivileged containers, the following profile is applied instead:
1717

1818
```yaml
1919
# incus profile create kubeadm-unprivileged
20-
# curl https://lxc.github.io/cluster-api-provider-incus/static/v0.1/profile.yaml | incus profile edit kubeadm-unprivileged
20+
# curl https://lxc.github.io/cluster-api-provider-incus/static/v0.1/unprivileged.yaml | incus profile edit kubeadm-unprivileged
2121

2222
{{#include ../../static/v0.1/unprivileged.yaml }}
2323
```
24+
25+
## Unprivileged containers (Canonical LXD)
26+
27+
When using unprivileged containers with Canonical LXD, it is also required to enable `security.nesting` and disable apparmor:
28+
29+
```bash
30+
# lxc profile create kubeadm-unprivileged
31+
# curl https://lxc.github.io/cluster-api-provider-incus/static/v0.1/unprivileged-lxd.yaml | lxc profile edit kubeadm-unprivileged
32+
33+
{{#include ../../static/v0.1/unprivileged-lxd.yaml }}
34+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../internal/static/embed/unprivileged-lxd.yaml

internal/controller/lxccluster/controller_delete.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func (r *LXCClusterReconciler) reconcileDelete(ctx context.Context, cluster *clu
2929
return ctrl.Result{}, err
3030
}
3131
conditions.MarkFalse(lxcCluster, infrav1.LoadBalancerAvailableCondition, clusterv1.DeletingReason, clusterv1.ConditionSeverityInfo, "")
32-
conditions.MarkFalse(lxcCluster, infrav1.KubeadmProfileAvailableCondition, clusterv1.DeletingReason, clusterv1.ConditionSeverityInfo, "")
3332
if err := patchLXCCluster(ctx, patchHelper, lxcCluster); err != nil {
3433
return ctrl.Result{}, fmt.Errorf("failed to patch LXCCluster: %w", err)
3534
}
@@ -48,11 +47,6 @@ func (r *LXCClusterReconciler) reconcileDelete(ctx context.Context, cluster *clu
4847
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
4948
}
5049

51-
log.FromContext(ctx).Info("Deleting default kubeadm profile")
52-
if err := lxcClient.DeleteProfile(lxcCluster.GetProfileName()); err != nil {
53-
return ctrl.Result{}, fmt.Errorf("failed to delete the default kubeadm profile: %w", err)
54-
}
55-
5650
// Cluster is deleted so remove the finalizer.
5751
controllerutil.RemoveFinalizer(lxcCluster, infrav1.ClusterFinalizer)
5852

internal/controller/lxccluster/controller_normal.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,18 @@ package lxccluster
22

33
import (
44
"context"
5-
"strings"
65

7-
"github.com/lxc/incus/v6/shared/api"
86
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
97
"sigs.k8s.io/cluster-api/util/conditions"
108
"sigs.k8s.io/controller-runtime/pkg/log"
119

1210
infrav1 "github.com/lxc/cluster-api-provider-incus/api/v1alpha2"
1311
"github.com/lxc/cluster-api-provider-incus/internal/loadbalancer"
1412
"github.com/lxc/cluster-api-provider-incus/internal/lxc"
15-
"github.com/lxc/cluster-api-provider-incus/internal/static"
1613
"github.com/lxc/cluster-api-provider-incus/internal/utils"
1714
)
1815

1916
func (r *LXCClusterReconciler) reconcileNormal(ctx context.Context, cluster *clusterv1.Cluster, lxcCluster *infrav1.LXCCluster, lxcClient *lxc.Client) error {
20-
// Create the default kubeadm profile for LXC containers
21-
profileName := lxcCluster.GetProfileName()
22-
if lxcCluster.Spec.SkipDefaultKubeadmProfile {
23-
// only log the message once, before the condition is set.
24-
if !conditions.Has(lxcCluster, infrav1.KubeadmProfileAvailableCondition) {
25-
log.FromContext(ctx).Info("Skipping kubeadm profile creation")
26-
}
27-
conditions.MarkTrue(lxcCluster, infrav1.KubeadmProfileAvailableCondition)
28-
} else {
29-
log := log.FromContext(ctx).WithValues("profileName", profileName)
30-
31-
if _, _, err := lxcClient.GetProfile(profileName); err != nil {
32-
if !strings.Contains(err.Error(), "Profile not found") {
33-
conditions.MarkFalse(lxcCluster, infrav1.KubeadmProfileAvailableCondition, infrav1.KubeadmProfileCreationFailedReason, clusterv1.ConditionSeverityWarning, "failed to check profile %q status: %s", profileName, err)
34-
return err
35-
}
36-
37-
log.Info("Creating default kubeadm profile for cluster")
38-
if err := lxcClient.CreateProfile(api.ProfilesPost{Name: profileName, ProfilePut: static.DefaultKubeadmProfile(!lxcCluster.Spec.Unprivileged)}); err != nil {
39-
log.Error(err, "Failed to create default kubeadm profile")
40-
41-
if strings.Contains(err.Error(), "Privileged containers are forbidden") {
42-
conditions.MarkFalse(lxcCluster, infrav1.KubeadmProfileAvailableCondition, infrav1.KubeadmProfileCreationAbortedReason, clusterv1.ConditionSeverityError, "The default kubeadm LXC profile could not be created, most likely because of a permissions issue. Either enable privileged containers on the project, or specify .spec.skipDefaultKubeadmProfile=true on the LXCCluster object. The error was: %s", err)
43-
return nil
44-
}
45-
conditions.MarkFalse(lxcCluster, infrav1.KubeadmProfileAvailableCondition, infrav1.KubeadmProfileCreationFailedReason, clusterv1.ConditionSeverityWarning, "%s", err)
46-
return err
47-
}
48-
}
49-
50-
conditions.MarkTrue(lxcCluster, infrav1.KubeadmProfileAvailableCondition)
51-
}
52-
5317
// Create the container hosting the load balancer.
5418
log.FromContext(ctx).Info("Creating load balancer")
5519
lbIPs, err := loadbalancer.ManagerForCluster(cluster, lxcCluster, lxcClient).Create(ctx)

internal/controller/lxccluster/controller_util.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
func patchLXCCluster(ctx context.Context, patchHelper *patch.Helper, lxcCluster *infrav1.LXCCluster) error {
1515
infraConditions := []clusterv1.ConditionType{
16-
infrav1.KubeadmProfileAvailableCondition,
1716
infrav1.LoadBalancerAvailableCondition,
1817
}
1918
hasInfraConditionError := false

0 commit comments

Comments
 (0)