Skip to content

Commit

Permalink
Cluster-API apiserver should be namespace-ed
Browse files Browse the repository at this point in the history
* templatize Namespace in ClusterAPIAPIServerConfigTemplate
* pass namespace to templating
* accept gen file edit
  • Loading branch information
ashish-amarnath committed Sep 20, 2018
1 parent 7db708b commit 81c3f14
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 98 deletions.
2 changes: 1 addition & 1 deletion clusterctl/clusterdeployer/clusterdeployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (d *ClusterDeployer) applyClusterAPIStackWithPivoting(client, source cluste
}

func (d *ClusterDeployer) applyClusterAPIApiserver(client clusterclient.Client, namespace string) error {
yaml, err := deployer.GetApiServerYaml()
yaml, err := deployer.GetApiServerYamlForNamespace(namespace)
if err != nil {
return fmt.Errorf("unable to generate apiserver yaml: %v", err)
}
Expand Down
176 changes: 88 additions & 88 deletions pkg/apis/cluster/zz_generated.api.register.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,66 +118,42 @@ func Resource(resource string) schema.GroupResource {
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Cluster struct {
type MachineDeployment struct {
metav1.TypeMeta
metav1.ObjectMeta
Spec ClusterSpec
Status ClusterStatus
Spec MachineDeploymentSpec
Status MachineDeploymentStatus
}

// +genclient
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type MachineSet struct {
type Machine struct {
metav1.TypeMeta
metav1.ObjectMeta
Spec MachineSetSpec
Status MachineSetStatus
}

type ClusterStatus struct {
APIEndpoints []APIEndpoint
ErrorReason clustercommon.ClusterStatusError
ErrorMessage string
ProviderStatus *pkgruntime.RawExtension
}

type MachineSetStatus struct {
Replicas int32
FullyLabeledReplicas int32
ReadyReplicas int32
AvailableReplicas int32
ObservedGeneration int64
ErrorReason *clustercommon.MachineSetStatusError
ErrorMessage *string
}

type APIEndpoint struct {
Host string
Port int
}

type MachineSetSpec struct {
Replicas *int32
MinReadySeconds int32
Selector metav1.LabelSelector
Template MachineTemplateSpec
}

type ClusterSpec struct {
ClusterNetwork ClusterNetworkingConfig
ProviderConfig ProviderConfig
Spec MachineSpec
Status MachineStatus
}

type MachineTemplateSpec struct {
metav1.ObjectMeta
Spec MachineSpec
type MachineDeploymentStatus struct {
ObservedGeneration int64
Replicas int32
UpdatedReplicas int32
ReadyReplicas int32
AvailableReplicas int32
UnavailableReplicas int32
}

type ProviderConfig struct {
Value *pkgruntime.RawExtension
ValueFrom *ProviderConfigSource
type MachineStatus struct {
NodeRef *corev1.ObjectReference
LastUpdated metav1.Time
Versions *MachineVersionInfo
ErrorReason *clustercommon.MachineStatusError
ErrorMessage *string
ProviderStatus *pkgruntime.RawExtension
Addresses []corev1.NodeAddress
Conditions []corev1.NodeCondition
}

type MachineSpec struct {
Expand All @@ -188,42 +164,14 @@ type MachineSpec struct {
ConfigSource *corev1.NodeConfigSource
}

type ProviderConfigSource struct {
}

type MachineVersionInfo struct {
Kubelet string
ControlPlane string
}

type ClusterNetworkingConfig struct {
Services NetworkRanges
Pods NetworkRanges
ServiceDomain string
}

// +genclient
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type MachineDeployment struct {
metav1.TypeMeta
metav1.ObjectMeta
Spec MachineDeploymentSpec
Status MachineDeploymentStatus
}

type NetworkRanges struct {
CIDRBlocks []string
}

type MachineDeploymentStatus struct {
ObservedGeneration int64
Replicas int32
UpdatedReplicas int32
ReadyReplicas int32
AvailableReplicas int32
UnavailableReplicas int32
type ProviderConfig struct {
Value *pkgruntime.RawExtension
ValueFrom *ProviderConfigSource
}

type MachineDeploymentSpec struct {
Expand All @@ -237,11 +185,19 @@ type MachineDeploymentSpec struct {
ProgressDeadlineSeconds *int32
}

type ProviderConfigSource struct {
}

type MachineDeploymentStrategy struct {
Type clustercommon.MachineDeploymentStrategyType
RollingUpdate *MachineRollingUpdateDeployment
}

type MachineTemplateSpec struct {
metav1.ObjectMeta
Spec MachineSpec
}

type MachineRollingUpdateDeployment struct {
MaxUnavailable *utilintstr.IntOrString
MaxSurge *utilintstr.IntOrString
Expand All @@ -251,22 +207,66 @@ type MachineRollingUpdateDeployment struct {
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Machine struct {
type Cluster struct {
metav1.TypeMeta
metav1.ObjectMeta
Spec MachineSpec
Status MachineStatus
Spec ClusterSpec
Status ClusterStatus
}

type MachineStatus struct {
NodeRef *corev1.ObjectReference
LastUpdated metav1.Time
Versions *MachineVersionInfo
ErrorReason *clustercommon.MachineStatusError
ErrorMessage *string
// +genclient
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type MachineSet struct {
metav1.TypeMeta
metav1.ObjectMeta
Spec MachineSetSpec
Status MachineSetStatus
}

type ClusterStatus struct {
APIEndpoints []APIEndpoint
ErrorReason clustercommon.ClusterStatusError
ErrorMessage string
ProviderStatus *pkgruntime.RawExtension
Addresses []corev1.NodeAddress
Conditions []corev1.NodeCondition
}

type MachineSetStatus struct {
Replicas int32
FullyLabeledReplicas int32
ReadyReplicas int32
AvailableReplicas int32
ObservedGeneration int64
ErrorReason *clustercommon.MachineSetStatusError
ErrorMessage *string
}

type APIEndpoint struct {
Host string
Port int
}

type MachineSetSpec struct {
Replicas *int32
MinReadySeconds int32
Selector metav1.LabelSelector
Template MachineTemplateSpec
}

type ClusterSpec struct {
ClusterNetwork ClusterNetworkingConfig
ProviderConfig ProviderConfig
}

type ClusterNetworkingConfig struct {
Services NetworkRanges
Pods NetworkRanges
ServiceDomain string
}

type NetworkRanges struct {
CIDRBlocks []string
}

//
Expand Down
9 changes: 8 additions & 1 deletion pkg/deployer/clusterapiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ func getApiServerCerts() (*caCertParams, error) {
return certParams, nil
}

// GetApiServerYaml returns the clusterapi-apiserver manifest used for deployment
// GetApiServerYaml returns the cluster-apiserver manifest for deployment in the default namespace
func GetApiServerYaml() (string, error) {
return GetApiServerYamlForNamespace(corev1.NamespaceDefault)
}

// GetApiServerYamlForNamespace returns the clusterapi-apiserver manifest used for deployment in the supplied namespace
func GetApiServerYamlForNamespace(namespace string) (string, error) {
tmpl, err := template.New("config").Parse(ClusterAPIAPIServerConfigTemplate)
if err != nil {
return "", err
Expand All @@ -94,6 +99,7 @@ func GetApiServerYaml() (string, error) {
CABundle string
TLSCrt string
TLSKey string
Namespace string
}

var tmplBuf bytes.Buffer
Expand All @@ -102,6 +108,7 @@ func GetApiServerYaml() (string, error) {
CABundle: certParms.caBundle,
TLSCrt: certParms.tlsCrt,
TLSKey: certParms.tlsKey,
Namespace: namespace,
})
if err != nil {
return "", err
Expand Down
16 changes: 8 additions & 8 deletions pkg/deployer/clusterapiservertemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ spec:
groupPriorityMinimum: 2000
service:
name: clusterapi
namespace: default
namespace: {{ .Namespace }}
versionPriority: 10
caBundle: {{ .CABundle }}
---
apiVersion: v1
kind: Service
metadata:
name: clusterapi
namespace: default
namespace: {{ .Namespace }}
labels:
api: clusterapi
apiserver: "true"
Expand All @@ -56,7 +56,7 @@ apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: clusterapi-apiserver
namespace: default
namespace: {{ .Namespace }}
labels:
api: clusterapi
apiserver: "true"
Expand Down Expand Up @@ -126,7 +126,7 @@ kind: ServiceAccount
apiVersion: v1
metadata:
name: apiserver
namespace: default
namespace: {{ .Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -139,7 +139,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: apiserver
namespace: default
namespace: {{ .Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand All @@ -153,13 +153,13 @@ roleRef:
subjects:
- kind: ServiceAccount
name: apiserver
namespace: default
namespace: {{ .Namespace }}
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: etcd-clusterapi
namespace: default
namespace: {{ .Namespace }}
spec:
serviceName: "etcd"
replicas: 1
Expand Down Expand Up @@ -250,7 +250,7 @@ kind: Secret
type: kubernetes.io/tls
metadata:
name: cluster-apiserver-certs
namespace: default
namespace: {{ .Namespace }}
labels:
api: clusterapi
apiserver: "true"
Expand Down

0 comments on commit 81c3f14

Please sign in to comment.