Skip to content

Commit

Permalink
revert approving own csr (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValyaB authored Oct 22, 2024
1 parent 1f59dbc commit feb9d3d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
4 changes: 2 additions & 2 deletions internal/actions/csr/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ func WatchCastAINodeCSRs(ctx context.Context, log logrus.FieldLogger, client kub
if csrResult == nil {
continue
}
// We are only interested in kubelet-bootstrap csr and our own service account csr.
if csrResult.RequestingUser != "kubelet-bootstrap" && csrResult.RequestingUser != "system:serviceaccount:castai-agent:castai-cluster-controller" {
// We are only interested in kubelet-bootstrap csr. SKIP own CSR due to the infinite loop of deleting->creating new->deleting.
if csrResult.RequestingUser != "kubelet-bootstrap" {
log.WithFields(logrus.Fields{
"csr": name,
"node_name": csrResult.RequestingUser,
Expand Down
32 changes: 0 additions & 32 deletions internal/actions/csr/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,6 @@ func TestCSRApprove(t *testing.T) {
r.Equal(csrResult.Status.Conditions[0].Type, certv1.CertificateApproved)
})

t.Run("approve v1 csr successfully which were created by controller", func(t *testing.T) {
r := require.New(t)
t.Parallel()

csrName := "node-csr-123"
userName := "system:serviceaccount:castai-agent:castai-cluster-controller"
client := fake.NewSimpleClientset(getCSR(csrName, userName))
s := NewApprovalManager(log, client)
watcher := watch.NewFake()
client.PrependWatchReactor("certificatesigningrequests", ktest.DefaultWatchReactor(watcher, nil))

ctx := context.Background()
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
s.Start(ctx)
}()
go func() {
defer wg.Done()
watcher.Add(getCSR(csrName, userName))
time.Sleep(100 * time.Millisecond)
s.Stop()
}()

wg.Wait()

csrResult, err := client.CertificatesV1().CertificateSigningRequests().Get(ctx, csrName, metav1.GetOptions{})
r.NoError(err)
r.Equal(csrResult.Status.Conditions[0].Type, certv1.CertificateApproved)
})

t.Run("not node csr do nothing", func(t *testing.T) {
r := require.New(t)
t.Parallel()
Expand Down

0 comments on commit feb9d3d

Please sign in to comment.