Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert approving own csr #149

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading