-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xuezhaojun <[email protected]>
- Loading branch information
1 parent
0f1f6b3
commit 985c552
Showing
8 changed files
with
278 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package flightctl | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/flightctl/flightctl/lib/apipublic/v1alpha1" | ||
"github.com/stolostron/managedcluster-import-controller/pkg/helpers" | ||
certificatesv1 "k8s.io/api/certificates/v1" | ||
) | ||
|
||
const FlightCtlNamespace = "flightctl" | ||
|
||
type FlightCtler interface { | ||
Login(ctx context.Context) error | ||
ApplyRepository(ctx context.Context) error | ||
GetDevice(ctx context.Context, deviceID string) (*v1alpha1.Device, error) | ||
CSRApprovalCondition(ctx context.Context, csr *certificatesv1.CertificateSigningRequest) (bool, error) | ||
} | ||
|
||
type FlightCtl struct { | ||
clientHolder *helpers.ClientHolder | ||
} | ||
|
||
var _ FlightCtler = &FlightCtl{} | ||
|
||
func (f *FlightCtl) Login(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
func (f *FlightCtl) ApplyRepository(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
func (f *FlightCtl) GetDevice(ctx context.Context, deviceID string) (*v1alpha1.Device, error) { | ||
return nil, nil | ||
} | ||
|
||
func (f *FlightCtl) CSRApprovalCondition(ctx context.Context, csr *certificatesv1.CertificateSigningRequest) (bool, error) { | ||
return false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package flightctl | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/openshift/library-go/pkg/operator/events" | ||
"github.com/stolostron/managedcluster-import-controller/pkg/helpers" | ||
clusterv1 "open-cluster-management.io/api/cluster/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/builder" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
const ManagedClusterControllerName = "flightctl-managedcluster-controller" | ||
|
||
// ManagedClusterReconciler is responsible to set hubAcceptsClient to true if the managed cluster is a flightctl device. | ||
type ManagedClusterReconciler struct { | ||
clientHolder *helpers.ClientHolder | ||
recorder events.Recorder | ||
} | ||
|
||
var _ reconcile.Reconciler = &ManagedClusterReconciler{} | ||
|
||
func (r *ManagedClusterReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { | ||
cluster := &clusterv1.ManagedCluster{} | ||
if err := r.clientHolder.RuntimeClient.Get(ctx, request.NamespacedName, cluster); err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
|
||
if cluster.DeletionTimestamp != nil { | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
if cluster.Spec.HubAcceptsClient { | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
cluster.Spec.HubAcceptsClient = true | ||
if err := r.clientHolder.RuntimeClient.Update(ctx, cluster); err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
|
||
return reconcile.Result{}, nil | ||
} | ||
|
||
func AddManagedClusterController(ctx context.Context, mgr manager.Manager, clientHolder *helpers.ClientHolder) error { | ||
err := ctrl.NewControllerManagedBy(mgr).Named(ManagedClusterControllerName). | ||
Watches( | ||
&clusterv1.ManagedCluster{}, | ||
&handler.EnqueueRequestForObject{}, | ||
builder.WithPredicates(predicate.Funcs{ | ||
GenericFunc: func(e event.GenericEvent) bool { return false }, | ||
DeleteFunc: func(e event.DeleteEvent) bool { return false }, | ||
UpdateFunc: func(e event.UpdateEvent) bool { | ||
return !e.ObjectNew.(*clusterv1.ManagedCluster).Spec.HubAcceptsClient | ||
}, | ||
CreateFunc: func(e event.CreateEvent) bool { | ||
return !e.Object.(*clusterv1.ManagedCluster).Spec.HubAcceptsClient | ||
}, | ||
})). | ||
Complete(&ManagedClusterReconciler{ | ||
clientHolder: clientHolder, | ||
recorder: helpers.NewEventRecorder(clientHolder.KubeClient, ManagedClusterControllerName), | ||
}) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: flightctl-client-agent-registration | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: managedcluster-import-controller-agent-regitration-client | ||
subjects: | ||
- kind: ServiceAccount | ||
name: flightctl-client | ||
namespace: "{{ .Namespace }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: flightctl-client |
7 changes: 7 additions & 0 deletions
7
pkg/controller/flightctl/manifests/serviceaccounttokensecret.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: flightctl-client-token | ||
annotations: | ||
kubernetes.io/service-account.name: flightctl-client | ||
type: kubernetes.io/service-account-token |
Oops, something went wrong.