Skip to content

Commit

Permalink
Merge pull request #201 from projectsyn/feature/dynamic-facts
Browse files Browse the repository at this point in the history
Add dynamic fact field to CRD
  • Loading branch information
glrf authored Aug 19, 2021
2 parents 37ba362 + fb96c44 commit 0b6221f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type BootstrapToken struct {
type ClusterStatus struct {
// BootstrapTokenValid validity of the bootstrap token, set by the Lieutenant API.
BootstrapToken *BootstrapToken `json:"bootstrapToken,omitempty"`
// Facts are key/value pairs for dynamically fetched facts
Facts Facts `json:"facts,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/crd/bases/syn.tools_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ spec:
format: date-time
type: string
type: object
facts:
additionalProperties:
type: string
description: Facts are key/value pairs for dynamically fetched facts
type: object
type: object
type: object
served: true
Expand Down
14 changes: 12 additions & 2 deletions controllers/cluster/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func createClusterRBAC(obj pipeline.Object, data *pipeline.Context) pipeline.Res
ObjectMeta: objMeta,
Rules: []rbacv1.PolicyRule{{
APIGroups: []string{synv1alpha1.GroupVersion.Group},
Resources: []string{"clusters"},
Resources: []string{"clusters", "clusters/status"},
Verbs: []string{"get", "update"},
ResourceNames: []string{obj.GetName()},
}},
Expand All @@ -41,7 +41,17 @@ func createClusterRBAC(obj pipeline.Object, data *pipeline.Context) pipeline.Res
}},
}
for _, item := range []client.Object{serviceAccount, role, roleBinding} {
if err := data.Client.Create(context.TODO(), item); err != nil && !errors.IsAlreadyExists(err) {
found := item.DeepCopyObject().(client.Object)
err := data.Client.Get(context.TODO(), client.ObjectKeyFromObject(item), found)
if err != nil {
if errors.IsNotFound(err) {
if err := data.Client.Create(context.TODO(), item); err != nil && !errors.IsAlreadyExists(err) {
return pipeline.Result{Err: err}
}
}
return pipeline.Result{Err: err}
}
if err := data.Client.Update(context.TODO(), item); err != nil {
return pipeline.Result{Err: err}
}
}
Expand Down

0 comments on commit 0b6221f

Please sign in to comment.