Skip to content

Commit ee5f175

Browse files
committed
feat: support lb as URL endpoint in machine configs and support machine deployments
Signed-off-by: Spencer Smith <[email protected]>
1 parent ac5d467 commit ee5f175

12 files changed

+302
-33
lines changed

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ resources:
55
- group: bootstrap
66
version: v1alpha2
77
kind: TalosConfig
8+
- group: bootstrap
9+
version: v1alpha2
10+
kind: TalosConfigTemplate
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package v1alpha2
15+
16+
import (
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
)
19+
20+
// TalosConfigTemplateSpec defines the desired state of TalosConfigTemplate
21+
type TalosConfigTemplateSpec struct {
22+
Template TalosConfigTemplateResource `json:"template"`
23+
}
24+
25+
// +kubebuilder:object:root=true
26+
// +kubebuilder:resource:path=talosconfigtemplates,scope=Namespaced,categories=cluster-api
27+
// +kubebuilder:storageversion
28+
29+
// TalosConfigTemplate is the Schema for the talosconfigtemplates API
30+
type TalosConfigTemplate struct {
31+
metav1.TypeMeta `json:",inline"`
32+
metav1.ObjectMeta `json:"metadata,omitempty"`
33+
34+
Spec TalosConfigTemplateSpec `json:"spec,omitempty"`
35+
}
36+
37+
// +kubebuilder:object:root=true
38+
39+
// TalosConfigTemplateList contains a list of TalosConfigTemplate
40+
type TalosConfigTemplateList struct {
41+
metav1.TypeMeta `json:",inline"`
42+
metav1.ListMeta `json:"metadata,omitempty"`
43+
Items []TalosConfigTemplate `json:"items"`
44+
}
45+
46+
func init() {
47+
SchemeBuilder.Register(&TalosConfigTemplate{}, &TalosConfigTemplateList{})
48+
}

api/v1alpha2/types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package v1alpha2
15+
16+
// TalosConfigTemplateResource defines the Template structure
17+
type TalosConfigTemplateResource struct {
18+
Spec TalosConfigSpec `json:"spec,omitempty"`
19+
}

api/v1alpha2/zz_generated.deepcopy.go

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
creationTimestamp: null
7+
name: talosconfigtemplates.bootstrap.cluster.x-k8s.io
8+
spec:
9+
group: bootstrap.cluster.x-k8s.io
10+
names:
11+
categories:
12+
- cluster-api
13+
kind: TalosConfigTemplate
14+
plural: talosconfigtemplates
15+
scope: Namespaced
16+
validation:
17+
openAPIV3Schema:
18+
description: TalosConfigTemplate is the Schema for the talosconfigtemplates
19+
API
20+
properties:
21+
apiVersion:
22+
description: 'APIVersion defines the versioned schema of this representation
23+
of an object. Servers should convert recognized schemas to the latest
24+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
25+
type: string
26+
kind:
27+
description: 'Kind is a string value representing the REST resource this
28+
object represents. Servers may infer this from the endpoint the client
29+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
30+
type: string
31+
metadata:
32+
type: object
33+
spec:
34+
description: TalosConfigTemplateSpec defines the desired state of TalosConfigTemplate
35+
properties:
36+
template:
37+
description: TalosConfigTemplateResource defines the Template structure
38+
properties:
39+
spec:
40+
description: TalosConfigSpec defines the desired state of TalosConfig
41+
properties:
42+
machineType:
43+
type: string
44+
type: object
45+
type: object
46+
required:
47+
- template
48+
type: object
49+
type: object
50+
version: v1alpha2
51+
versions:
52+
- name: v1alpha2
53+
served: true
54+
storage: true
55+
status:
56+
acceptedNames:
57+
kind: ""
58+
plural: ""
59+
conditions: []
60+
storedVersions: []

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# It should be run by config/default
44
resources:
55
- bases/bootstrap.cluster.x-k8s.io_talosconfigs.yaml
6+
- bases/bootstrap.cluster.x-k8s.io_talosconfigtemplates.yaml
67
# +kubebuilder:scaffold:crdkustomizeresource
78

89
patchesStrategicMerge:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: talosconfigtemplates.bootstrap.cluster.x-k8s.io
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: talosconfigtemplates.bootstrap.cluster.x-k8s.io
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13+
caBundle: Cg==
14+
service:
15+
namespace: system
16+
name: webhook-service
17+
path: /convert

controllers/secrets.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,38 @@ import (
2222
"github.com/talos-systems/talos/pkg/config/types/v1alpha1/generate"
2323
"gopkg.in/yaml.v2"
2424
corev1 "k8s.io/api/core/v1"
25-
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"sigs.k8s.io/controller-runtime/pkg/client"
2827
)
2928

30-
func (r *TalosConfigReconciler) fetchCertSecret(ctx context.Context, config *bootstrapv1alpha2.TalosConfig, clusterName string) (*corev1.Secret, error) {
29+
func (r *TalosConfigReconciler) fetchInputSecret(ctx context.Context, config *bootstrapv1alpha2.TalosConfig, clusterName string) (*corev1.Secret, error) {
3130

32-
certSecret := &corev1.Secret{}
31+
inputSecret := &corev1.Secret{}
3332
err := r.Client.Get(context.Background(), client.ObjectKey{
3433
Namespace: config.GetNamespace(),
3534
Name: clusterName,
36-
}, certSecret)
35+
}, inputSecret)
3736

38-
if err != nil && k8serrors.IsNotFound(err) {
39-
return nil, nil
40-
} else if err != nil {
37+
if err != nil {
4138
return nil, err
4239
}
4340

44-
return certSecret, nil
41+
return inputSecret, nil
4542
}
4643

47-
func (r *TalosConfigReconciler) writeCertSecret(ctx context.Context, config *bootstrapv1alpha2.TalosConfig, clusterName string, certs *generate.Certs) error {
44+
func (r *TalosConfigReconciler) writeInputSecret(ctx context.Context, config *bootstrapv1alpha2.TalosConfig, clusterName string, input *generate.Input) error {
45+
46+
certMarshal, err := yaml.Marshal(input.Certs)
47+
if err != nil {
48+
return err
49+
}
50+
51+
kubeTokenMarshal, err := yaml.Marshal(input.KubeadmTokens)
52+
if err != nil {
53+
return err
54+
}
4855

49-
certMarshal, err := yaml.Marshal(certs)
56+
trustdInfoMarshal, err := yaml.Marshal(input.TrustdInfo)
5057
if err != nil {
5158
return err
5259
}
@@ -56,7 +63,11 @@ func (r *TalosConfigReconciler) writeCertSecret(ctx context.Context, config *boo
5663
Namespace: config.GetNamespace(),
5764
Name: clusterName,
5865
},
59-
Data: map[string][]byte{"certs": certMarshal},
66+
Data: map[string][]byte{
67+
"certs": certMarshal,
68+
"kubeTokens": kubeTokenMarshal,
69+
"trustdInfo": trustdInfoMarshal,
70+
},
6071
}
6172

6273
err = r.Client.Create(ctx, certSecret)

0 commit comments

Comments
 (0)