Skip to content

Commit

Permalink
Merge pull request #3107 from sedefsavas/clusterresourceset_
Browse files Browse the repository at this point in the history
✨ Introduce ClusterResourceSet experimental API and controllers
  • Loading branch information
k8s-ci-robot authored Jul 7, 2020
2 parents 9a2aa08 + add44ad commit c6e7711
Show file tree
Hide file tree
Showing 36 changed files with 3,030 additions and 65 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ generate-go-core: $(CONTROLLER_GEN) $(CONVERSION_GEN)
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
paths=./api/... \
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/addons/api/... \
paths=./cmd/clusterctl/...
$(CONVERSION_GEN) \
--input-dirs=./api/v1alpha2 \
Expand Down Expand Up @@ -271,6 +272,8 @@ generate-core-manifests: $(CONTROLLER_GEN) ## Generate manifests for the core pr
paths=./controllers/... \
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/controllers/... \
paths=./$(EXP_DIR)/addons/api/... \
paths=./$(EXP_DIR)/addons/controllers/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
output:crd:dir=./config/crd/bases \
Expand Down
4 changes: 3 additions & 1 deletion cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
manifests "sigs.k8s.io/cluster-api/cmd/clusterctl/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
utilresource "sigs.k8s.io/cluster-api/util/resource"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -120,7 +121,7 @@ func (cm *certManagerClient) EnsureWebhook() error {

// installs the web-hook
createCertManagerBackoff := newWriteBackoff()
objs = sortResourcesForCreate(objs)
objs = utilresource.SortForCreate(objs)
for i := range objs {
o := objs[i]
log.V(5).Info("Creating", logf.UnstructuredToValues(o)...)
Expand Down Expand Up @@ -182,6 +183,7 @@ func (cm *certManagerClient) getManifestObjs() ([]unstructured.Unstructured, err
}

objs, err := utilyaml.ToUnstructured(yaml)

if err != nil {
return nil, errors.Wrap(err, "failed to parse yaml for cert-manager manifest")
}
Expand Down
56 changes: 0 additions & 56 deletions cmd/clusterctl/client/cluster/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,59 +217,3 @@ func newComponentsClient(proxy Proxy) *providerComponents {
proxy: proxy,
}
}

var defaultCreatePriorities = []string{
// Namespaces go first because all namespaced resources depend on them.
"Namespace",
// Custom Resource Definitions come before Custom Resource so that they can be
// restored with their corresponding CRD.
"CustomResourceDefinition",
// Storage Classes are needed to create PVs and PVCs correctly.
"StorageClass",
// PVs go before PVCs because PVCs depend on them.
"PersistentVolume",
// PVCs go before pods or controllers so they can be mounted as volumes.
"PersistentVolumeClaim",
// Secrets and ConfigMaps go before pods or controllers so they can be mounted as volumes.
"Secret",
"ConfigMap",
// Service accounts go before pods or controllers so pods can use them.
"ServiceAccount",
// Limit ranges go before pods or controllers so pods can use them.
"LimitRange",
// Pods go before ReplicaSets
"Pods",
// ReplicaSets go before Deployments
"ReplicaSet",
// Endpoints go before Services
"Endpoints",
}

func sortResourcesForCreate(resources []unstructured.Unstructured) []unstructured.Unstructured {
var ret []unstructured.Unstructured

// First get resources by priority
for _, p := range defaultCreatePriorities {
for _, o := range resources {
if o.GetKind() == p {
ret = append(ret, o)
}
}
}

// Then get all the other resources
for _, o := range resources {
found := false
for _, r := range ret {
if o.GroupVersionKind() == r.GroupVersionKind() && o.GetNamespace() == r.GetNamespace() && o.GetName() == r.GetName() {
found = true
break
}
}
if !found {
ret = append(ret, o)
}
}

return ret
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.9
creationTimestamp: null
name: clusterresourcesetbindings.addons.cluster.x-k8s.io
spec:
group: addons.cluster.x-k8s.io
names:
categories:
- cluster-api
kind: ClusterResourceSetBinding
listKind: ClusterResourceSetBindingList
plural: clusterresourcesetbindings
singular: clusterresourcesetbinding
scope: Namespaced
versions:
- name: v1alpha3
schema:
openAPIV3Schema:
description: ClusterResourceSetBinding lists all matching ClusterResourceSets
with the cluster it belongs to.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ClusterResourceSetBindingSpec defines the desired state of
ClusterResourceSetBinding
properties:
bindings:
additionalProperties:
description: ResourcesSetBinding keeps info on all of the resources
in a ClusterResourceSet.
properties:
resources:
additionalProperties:
description: ResourceBinding shows the status of a resource
that belongs to a ClusterResourceSet matched by the owner
cluster of the ClusterResourceSetBinding object.
properties:
applied:
description: Applied is to track if a resource is applied
to the cluster or not.
type: boolean
hash:
description: Hash is the hash of a resource's data. This
can be used to decide if a resource is changed. For
"ApplyOnce" ClusterResourceSet.spec.strategy, this is
no-op as that strategy does not act on change.
type: string
lastAppliedTime:
description: LastAppliedTime identifies when this resource
was last applied to the cluster.
format: date-time
type: string
required:
- applied
type: object
description: 'Resources is a map of Secrets/ConfigMaps and their
ResourceBinding. The map''s key is a concatenated string of
form: <resource-type>/<resource-name>.'
type: object
type: object
description: Bindings is a map of ClusterResourceSet name and its
resources which is also a map.
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
183 changes: 183 additions & 0 deletions config/crd/bases/addons.cluster.x-k8s.io_clusterresourcesets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.9
creationTimestamp: null
name: clusterresourcesets.addons.cluster.x-k8s.io
spec:
group: addons.cluster.x-k8s.io
names:
categories:
- cluster-api
kind: ClusterResourceSet
listKind: ClusterResourceSetList
plural: clusterresourcesets
singular: clusterresourceset
scope: Namespaced
versions:
- name: v1alpha3
schema:
openAPIV3Schema:
description: ClusterResourceSet is the Schema for the clusterresourcesets
API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ClusterResourceSetSpec defines the desired state of ClusterResourceSet
properties:
clusterSelector:
description: Label selector for Clusters. The Clusters that are selected
by this will be the ones affected by this ClusterResourceSet. It
must match the Cluster labels. This field is immutable.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
resources:
description: Resources is a list of Secrets/ConfigMaps where each
contains 1 or more resources to be applied to remote clusters.
items:
description: ResourceRef specifies a resource.
properties:
kind:
description: 'Kind of the resource. Supported kinds are: Secrets
and ConfigMaps.'
enum:
- Secret
- ConfigMap
type: string
name:
description: Name of the resource that is in the same namespace
with ClusterResourceSet object.
minLength: 1
type: string
required:
- kind
- name
type: object
type: array
strategy:
description: Strategy is the strategy to be used during applying resources.
Defaults to ApplyOnce. This field is immutable.
enum:
- ApplyOnce
type: string
required:
- clusterSelector
type: object
status:
description: ClusterResourceSetStatus defines the observed state of ClusterResourceSet
properties:
conditions:
description: Conditions defines current state of the ClusterResourceSet.
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase. The specific API may choose whether or not this
field is considered a guaranteed API. This field may not be
empty.
type: string
severity:
description: Severity provides an explicit classification of
Reason code, so the users or machines can immediately understand
the current situation and act accordingly. The Severity field
MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important.
type: string
required:
- status
- type
type: object
type: array
observedGeneration:
description: ObservedGeneration reflects the generation of the most
recently observed ClusterResourceSet.
format: int64
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ resources:
- bases/cluster.x-k8s.io_machinesets.yaml
- bases/cluster.x-k8s.io_machinedeployments.yaml
- bases/exp.cluster.x-k8s.io_machinepools.yaml
- bases/addons.cluster.x-k8s.io_clusterresourcesets.yaml
- bases/addons.cluster.x-k8s.io_clusterresourcesetbindings.yaml
- bases/cluster.x-k8s.io_machinehealthchecks.yaml
# +kubebuilder:scaffold:crdkustomizeresource

Expand Down
Loading

0 comments on commit c6e7711

Please sign in to comment.