-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
certs, Add Certs list size limit Currently certs are appended without limit. This can cause a problem when applying the caBundle/certs on the mutatingwebhookconfiguration/secret, appropriately - due to etcd's POST size limit. Limited the amount of certs to 100. Signed-off-by: Ram Lavi <[email protected]>
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 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,15 @@ | ||
package triple | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
"github.com/onsi/ginkgo/reporters" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestTriple(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
junitReporter := reporters.NewJUnitReporter("junit.triple_suite_test.xml") | ||
RunSpecsWithDefaultAndCustomReporters(t, "Certificate Test Suite", []Reporter{junitReporter}) | ||
} |
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,55 @@ | ||
package triple | ||
|
||
import ( | ||
"crypto/x509" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Cert library", func() { | ||
|
||
type removeOldestCertsParams struct { | ||
certsList []*x509.Certificate | ||
maxListSize int | ||
expectedCertsList []*x509.Certificate | ||
} | ||
certOldest := &x509.Certificate{ | ||
NotBefore: time.Now().Add(10*time.Hour), | ||
NotAfter: time.Now(), | ||
} | ||
certOld := &x509.Certificate{ | ||
NotBefore: time.Now().Add(5*time.Hour), | ||
NotAfter: time.Now(), | ||
} | ||
certCurrent := &x509.Certificate{ | ||
NotBefore: time.Now(), | ||
NotAfter: time.Now(), | ||
} | ||
|
||
DescribeTable("removeOldestCerts", | ||
func(c removeOldestCertsParams) { | ||
Expect(RemoveOldestCerts(c.certsList, c.maxListSize)).To(ConsistOf(c.expectedCertsList), "should remove the oldest certs") | ||
}, | ||
Entry("when list is empty", | ||
removeOldestCertsParams{ | ||
certsList: []*x509.Certificate{}, | ||
maxListSize: 2, | ||
expectedCertsList: []*x509.Certificate{}, | ||
}), | ||
Entry("when list size is less or equal to max certs, should keep the certs list intact", | ||
removeOldestCertsParams{ | ||
certsList: []*x509.Certificate{certOldest, certOld, certCurrent}, | ||
maxListSize: 3, | ||
expectedCertsList: []*x509.Certificate{certOldest, certOld, certCurrent}, | ||
}), | ||
Entry("when list size is bigger than max certs, should remove the oldest certs", | ||
removeOldestCertsParams{ | ||
certsList: []*x509.Certificate{certOldest, certOld, certCurrent}, | ||
maxListSize: 2, | ||
expectedCertsList: []*x509.Certificate{certOld, certCurrent}, | ||
}), | ||
) | ||
}) |