mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 07:26:55 +00:00
feat(perf): add new linter prealloc
to enforce slice declarations best practice (#10250)
* feat(perf): add new linter prealloc to enforce slice declarations best practice Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix(linter): prealloac slices Signed-off-by: ShutingZhao <shuting@nirmata.com> --------- Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
46e5d818b1
commit
fb9c66f455
37 changed files with 50 additions and 50 deletions
|
@ -38,6 +38,7 @@ linters:
|
|||
- unused
|
||||
- wastedassign
|
||||
- whitespace
|
||||
- prealloc
|
||||
|
||||
run:
|
||||
timeout: 15m
|
||||
|
|
|
@ -264,7 +264,7 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
}
|
||||
var rc processor.ResultCounts
|
||||
// validate policies
|
||||
var validPolicies []kyvernov1.PolicyInterface
|
||||
validPolicies := make([]kyvernov1.PolicyInterface, 0, len(policies))
|
||||
for _, pol := range policies {
|
||||
// TODO we should return this info to the caller
|
||||
_, err := policyvalidation.Validate(pol, nil, nil, nil, true, config.KyvernoUserName(config.KyvernoServiceAccountName()))
|
||||
|
|
|
@ -68,7 +68,7 @@ func (o options) processFile(out io.Writer, path string) {
|
|||
if len(policies) == 0 {
|
||||
return
|
||||
}
|
||||
var fixed []kyvernov1.PolicyInterface
|
||||
fixed := make([]kyvernov1.PolicyInterface, 0, len(policies))
|
||||
for _, policy := range policies {
|
||||
copy := policy.CreateDeepCopy()
|
||||
fmt.Fprintf(out, "Processing file (%s)...\n", path)
|
||||
|
|
|
@ -62,7 +62,7 @@ func loadFile(cmd *cobra.Command, file string) (string, error) {
|
|||
}
|
||||
|
||||
func loadExpressions(cmd *cobra.Command, args []string, files []string) ([]string, error) {
|
||||
var expressions []string
|
||||
expressions := make([]string, 0, len(args))
|
||||
expressions = append(expressions, args...)
|
||||
for _, file := range files {
|
||||
expression, err := loadFile(cmd, file)
|
||||
|
|
|
@ -107,7 +107,7 @@ func readQuery(cmd *cobra.Command) (string, error) {
|
|||
}
|
||||
|
||||
func loadQueries(cmd *cobra.Command, args []string, files []string) ([]string, error) {
|
||||
var queries []string
|
||||
queries := make([]string, 0, len(args))
|
||||
queries = append(queries, args...)
|
||||
for _, file := range files {
|
||||
query, err := loadFile(cmd, file)
|
||||
|
|
|
@ -76,7 +76,7 @@ func (c *options) run(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
out.println("Running", "(", "evaluating", len(resources), pluralize.Pluralize(len(resources), "resource", "resources"), "against", len(policies), pluralize.Pluralize(len(policies), "policy", "policies"), ")", "...")
|
||||
e := jsonengine.New()
|
||||
var responses []jsonengine.Response
|
||||
responses := make([]jsonengine.Response, 0, len(resources))
|
||||
for _, resource := range resources {
|
||||
responses = append(responses, e.Run(context.Background(), jsonengine.Request{
|
||||
Resource: resource,
|
||||
|
|
|
@ -183,7 +183,7 @@ func checkResult(test v1alpha1.TestResult, fs billy.Filesystem, resoucePath stri
|
|||
}
|
||||
|
||||
func lookupEngineResponses(test v1alpha1.TestResult, resourceName string, responses ...engineapi.EngineResponse) []engineapi.EngineResponse {
|
||||
var matches []engineapi.EngineResponse
|
||||
matches := make([]engineapi.EngineResponse, 0, len(responses))
|
||||
for _, response := range responses {
|
||||
policy := response.Policy()
|
||||
resource := response.Resource
|
||||
|
|
|
@ -142,7 +142,7 @@ func runTest(out io.Writer, testCase test.TestCase, registryAccess bool, auditWa
|
|||
}
|
||||
}
|
||||
// validate policies
|
||||
var validPolicies []kyvernov1.PolicyInterface
|
||||
validPolicies := make([]kyvernov1.PolicyInterface, 0, len(policies))
|
||||
for _, pol := range policies {
|
||||
// TODO we should return this info to the caller
|
||||
_, err := policyvalidation.Validate(pol, nil, nil, nil, true, config.KyvernoUserName(config.KyvernoServiceAccountName()))
|
||||
|
|
|
@ -31,7 +31,7 @@ func FixTest(test v1alpha1.Test, compress bool) (v1alpha1.Test, []string, error)
|
|||
if len(test.Resources) == 0 {
|
||||
messages = append(messages, "test has no resources")
|
||||
}
|
||||
var results []v1alpha1.TestResult
|
||||
results := make([]v1alpha1.TestResult, 0, len(test.Results))
|
||||
for _, result := range test.Results {
|
||||
if result.Resource != "" && len(result.Resources) != 0 {
|
||||
messages = append(messages, "test result should not use both `resource` and `resources` fields")
|
||||
|
|
|
@ -20,7 +20,7 @@ func (t *Table) Rows(detailed bool) interface{} {
|
|||
if detailed {
|
||||
return t.RawRows
|
||||
}
|
||||
var rows []RowCompact
|
||||
rows := make([]RowCompact, 0, len(t.RawRows))
|
||||
for _, row := range t.RawRows {
|
||||
rows = append(rows, row.RowCompact)
|
||||
}
|
||||
|
|
|
@ -85,7 +85,6 @@ func TestTable_AddFailed(t *testing.T) {
|
|||
|
||||
func TestTable_Rows(t *testing.T) {
|
||||
var nilRows []Row
|
||||
var nilCompactRows []RowCompact
|
||||
tests := []struct {
|
||||
name string
|
||||
RawRows []Row
|
||||
|
@ -93,7 +92,7 @@ func TestTable_Rows(t *testing.T) {
|
|||
want interface{}
|
||||
}{{
|
||||
name: "nil",
|
||||
want: nilCompactRows,
|
||||
want: []RowCompact{},
|
||||
}, {
|
||||
name: "nil - detailed",
|
||||
detailed: true,
|
||||
|
@ -186,13 +185,13 @@ func TestTable_Rows(t *testing.T) {
|
|||
Message: "message2",
|
||||
}},
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
for i, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tr := &Table{
|
||||
RawRows: tt.RawRows,
|
||||
}
|
||||
if got := tr.Rows(tt.detailed); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Table.Rows() = %v, want %v", got, tt.want)
|
||||
t.Errorf("test=%v, Table.Rows() = %v, want %v", i, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func GetFullPaths(paths []string, basePath string, git bool) []string {
|
|||
if git {
|
||||
return paths
|
||||
}
|
||||
var out []string
|
||||
out := make([]string, 0, len(paths))
|
||||
for _, path := range paths {
|
||||
out = append(out, GetFullPath(path, basePath))
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ func (p *PolicyProcessor) ApplyPoliciesOnResource() ([]engineapi.EngineResponse,
|
|||
}
|
||||
}
|
||||
resPath := fmt.Sprintf("%s/%s/%s", resource.GetNamespace(), resource.GetKind(), resource.GetName())
|
||||
var responses []engineapi.EngineResponse
|
||||
responses := make([]engineapi.EngineResponse, 0, len(p.Policies))
|
||||
// mutate
|
||||
for _, policy := range p.Policies {
|
||||
if !policy.GetSpec().HasMutate() {
|
||||
|
|
|
@ -19,7 +19,7 @@ type ValidatingAdmissionPolicyProcessor struct {
|
|||
}
|
||||
|
||||
func (p *ValidatingAdmissionPolicyProcessor) ApplyPolicyOnResource() ([]engineapi.EngineResponse, error) {
|
||||
var responses []engineapi.EngineResponse
|
||||
responses := make([]engineapi.EngineResponse, 0, len(p.Policies))
|
||||
for _, policy := range p.Policies {
|
||||
policyData := validatingadmissionpolicy.NewPolicyData(policy)
|
||||
for _, binding := range p.Bindings {
|
||||
|
|
|
@ -19,11 +19,11 @@ import (
|
|||
)
|
||||
|
||||
func GetUnstructuredResources(resourceBytes []byte) ([]*unstructured.Unstructured, error) {
|
||||
var resources []*unstructured.Unstructured
|
||||
documents, err := yamlutils.SplitDocuments(resourceBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resources := make([]*unstructured.Unstructured, 0, len(documents))
|
||||
for _, document := range documents {
|
||||
resource, err := YamlToUnstructured(document)
|
||||
if err != nil {
|
||||
|
|
|
@ -20,7 +20,6 @@ func (r *KyvernoResources) FetchResourcesFromPolicy(out io.Writer, resourcePaths
|
|||
var err error
|
||||
|
||||
resourceTypesMap := make(map[schema.GroupVersionKind]bool)
|
||||
var resourceTypes []schema.GroupVersionKind
|
||||
var subresourceMap map[schema.GroupVersionKind]v1alpha1.Subresource
|
||||
|
||||
for _, policy := range r.policies {
|
||||
|
@ -33,6 +32,7 @@ func (r *KyvernoResources) FetchResourcesFromPolicy(out io.Writer, resourcePaths
|
|||
}
|
||||
}
|
||||
|
||||
resourceTypes := make([]schema.GroupVersionKind, 0, len(resourceTypesMap))
|
||||
for kind := range resourceTypesMap {
|
||||
resourceTypes = append(resourceTypes, kind)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ func (r *ValidatingAdmissionResources) FetchResourcesFromPolicy(out io.Writer, r
|
|||
var err error
|
||||
|
||||
resourceTypesMap := make(map[schema.GroupVersionKind]bool)
|
||||
var resourceTypes []schema.GroupVersionKind
|
||||
var subresourceMap map[schema.GroupVersionKind]v1alpha1.Subresource
|
||||
|
||||
for _, policy := range r.policies {
|
||||
|
@ -33,6 +32,7 @@ func (r *ValidatingAdmissionResources) FetchResourcesFromPolicy(out io.Writer, r
|
|||
}
|
||||
}
|
||||
|
||||
resourceTypes := make([]schema.GroupVersionKind, 0, len(resourceTypesMap))
|
||||
for kind := range resourceTypesMap {
|
||||
resourceTypes = append(resourceTypes, kind)
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ func checkAutogenSupport(needed *bool, subjects ...kyvernov1.ResourceDescription
|
|||
|
||||
// stripCronJob removes CronJob from controllers
|
||||
func stripCronJob(controllers string) string {
|
||||
var newControllers []string
|
||||
controllerArr := splitKinds(controllers, ",")
|
||||
newControllers := make([]string, 0, len(controllerArr))
|
||||
for _, c := range controllerArr {
|
||||
if c == PodControllerCronJob {
|
||||
continue
|
||||
|
|
|
@ -419,7 +419,7 @@ func (c *controller) backReconcile(ctx context.Context, logger logr.Logger, _, n
|
|||
reports = append(reports, ephemeralReports...)
|
||||
merged := map[string]policyreportv1alpha2.PolicyReportResult{}
|
||||
mergeReports(policyMap, vapMap, merged, types.UID(name), reports...)
|
||||
var results []policyreportv1alpha2.PolicyReportResult
|
||||
results := make([]policyreportv1alpha2.PolicyReportResult, 0, len(merged))
|
||||
for _, result := range merged {
|
||||
results = append(results, result)
|
||||
}
|
||||
|
|
|
@ -503,7 +503,7 @@ func (c *controller) reconcile(ctx context.Context, log logr.Logger, key, namesp
|
|||
}
|
||||
// load background policies
|
||||
kyvernoPolicies = utils.RemoveNonBackgroundPolicies(kyvernoPolicies...)
|
||||
var policies []engineapi.GenericPolicy
|
||||
policies := make([]engineapi.GenericPolicy, 0, len(kyvernoPolicies))
|
||||
for _, pol := range kyvernoPolicies {
|
||||
policies = append(policies, engineapi.NewKyvernoPolicy(pol))
|
||||
}
|
||||
|
|
|
@ -737,7 +737,7 @@ func (c *controller) buildResourceMutatingWebhookConfiguration(ctx context.Conte
|
|||
}
|
||||
|
||||
func (c *controller) buildResourceMutatingWebhookRules(caBundle []byte, webhookCfg config.WebhookConfig, sideEffects *admissionregistrationv1.SideEffectClass, webhooks []*webhook, mapResourceToOpnType map[string][]admissionregistrationv1.OperationType) []admissionregistrationv1.MutatingWebhook {
|
||||
var mutatingWebhooks []admissionregistrationv1.MutatingWebhook
|
||||
mutatingWebhooks := make([]admissionregistrationv1.MutatingWebhook, 0, len(webhooks))
|
||||
for _, webhook := range webhooks {
|
||||
if webhook.isEmpty() {
|
||||
continue
|
||||
|
@ -911,7 +911,7 @@ func (c *controller) buildResourceValidatingWebhookConfiguration(ctx context.Con
|
|||
}
|
||||
|
||||
func (c *controller) buildResourceValidatingWebhookRules(caBundle []byte, webhookCfg config.WebhookConfig, sideEffects *admissionregistrationv1.SideEffectClass, webhooks []*webhook, mapResourceToOpnType map[string][]admissionregistrationv1.OperationType) []admissionregistrationv1.ValidatingWebhook {
|
||||
var validatingWebhooks []admissionregistrationv1.ValidatingWebhook
|
||||
validatingWebhooks := make([]admissionregistrationv1.ValidatingWebhook, 0, len(webhooks))
|
||||
for _, webhook := range webhooks {
|
||||
if webhook.isEmpty() {
|
||||
continue
|
||||
|
|
|
@ -72,7 +72,7 @@ func newWebhookPerPolicy(timeout int32, failurePolicy admissionregistrationv1.Fa
|
|||
}
|
||||
|
||||
func (wh *webhook) buildRulesWithOperations(final map[string][]admissionregistrationv1.OperationType, defaultOpn []admissionregistrationv1.OperationType) []admissionregistrationv1.RuleWithOperations {
|
||||
var rules []admissionregistrationv1.RuleWithOperations
|
||||
rules := make([]admissionregistrationv1.RuleWithOperations, 0, len(wh.rules))
|
||||
|
||||
for gv, resources := range wh.rules {
|
||||
firstResource := sets.List(resources)[0]
|
||||
|
|
|
@ -471,7 +471,7 @@ func decodePEM(raw []byte, signatureAlgorithm crypto.Hash) (signature.Verifier,
|
|||
}
|
||||
|
||||
func extractPayload(verified []oci.Signature) ([]payload.SimpleContainerImage, error) {
|
||||
var sigPayloads []payload.SimpleContainerImage
|
||||
sigPayloads := make([]payload.SimpleContainerImage, 0, len(verified))
|
||||
for _, sig := range verified {
|
||||
pld, err := sig.Payload()
|
||||
if err != nil {
|
||||
|
|
|
@ -30,7 +30,7 @@ func (a *dclientAdapter) GetResources(ctx context.Context, group, version, kind,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result []engineapi.Resource
|
||||
result := make([]engineapi.Resource, 0, len(resources))
|
||||
for _, resource := range resources {
|
||||
result = append(result, engineapi.Resource{
|
||||
Group: resource.Group,
|
||||
|
|
|
@ -82,7 +82,6 @@ func resolveSpec(i int, target kyvernov1.TargetResourceSpec, ctx engineapi.Polic
|
|||
}
|
||||
|
||||
func getTargets(ctx context.Context, client engineapi.Client, target kyvernov1.ResourceSpec, policyCtx engineapi.PolicyContext) ([]resourceInfo, error) {
|
||||
var targetObjects []resourceInfo
|
||||
namespace := target.Namespace
|
||||
name := target.Name
|
||||
policy := policyCtx.Policy()
|
||||
|
@ -95,6 +94,7 @@ func getTargets(ctx context.Context, client engineapi.Client, target kyvernov1.R
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
targetObjects := make([]resourceInfo, 0, len(resources))
|
||||
for _, resource := range resources {
|
||||
targetObjects = append(targetObjects, resourceInfo{
|
||||
unstructured: resource.Unstructured,
|
||||
|
|
|
@ -162,7 +162,7 @@ func addImages(checks []pssutils.PSSCheckResult, imageInfos map[string]map[strin
|
|||
|
||||
// return image references for containers
|
||||
func getImages(containerNames []string, imageInfos map[string]map[string]api.ImageInfo) []string {
|
||||
var images []string
|
||||
images := make([]string, 0, len(containerNames))
|
||||
for _, cn := range containerNames {
|
||||
image := getImageReference(cn, imageInfos)
|
||||
images = append(images, image)
|
||||
|
|
|
@ -138,7 +138,7 @@ func isImageVerified(resource unstructured.Unstructured, image string, log logr.
|
|||
}
|
||||
|
||||
func ExpandStaticKeys(attestorSet kyvernov1.AttestorSet) kyvernov1.AttestorSet {
|
||||
var entries []kyvernov1.Attestor
|
||||
entries := make([]kyvernov1.Attestor, 0, len(attestorSet.Entries))
|
||||
for _, e := range attestorSet.Entries {
|
||||
if e.Keys != nil {
|
||||
keys := splitPEM(e.Keys.PublicKeys)
|
||||
|
@ -165,7 +165,7 @@ func splitPEM(pem string) []string {
|
|||
}
|
||||
|
||||
func createStaticKeyAttestors(keys []string) []kyvernov1.Attestor {
|
||||
var attestors []kyvernov1.Attestor
|
||||
attestors := make([]kyvernov1.Attestor, 0, len(keys))
|
||||
for _, k := range keys {
|
||||
a := kyvernov1.Attestor{
|
||||
Keys: &kyvernov1.StaticKeyAttestor{
|
||||
|
@ -179,7 +179,7 @@ func createStaticKeyAttestors(keys []string) []kyvernov1.Attestor {
|
|||
|
||||
func buildStatementMap(statements []map[string]interface{}) (map[string][]map[string]interface{}, []string) {
|
||||
results := map[string][]map[string]interface{}{}
|
||||
var predicateTypes []string
|
||||
predicateTypes := make([]string, 0, len(statements))
|
||||
for _, s := range statements {
|
||||
predicateType := s["type"].(string)
|
||||
if results[predicateType] != nil {
|
||||
|
|
|
@ -32,7 +32,7 @@ func (f FunctionEntry) String() string {
|
|||
if f.Name == "" {
|
||||
return ""
|
||||
}
|
||||
var args []string
|
||||
args := make([]string, 0, len(f.Arguments))
|
||||
for _, a := range f.Arguments {
|
||||
var aTypes []string
|
||||
for _, t := range a.Types {
|
||||
|
@ -40,7 +40,7 @@ func (f FunctionEntry) String() string {
|
|||
}
|
||||
args = append(args, strings.Join(aTypes, "|"))
|
||||
}
|
||||
var returnArgs []string
|
||||
returnArgs := make([]string, 0, len(f.ReturnType))
|
||||
for _, ra := range f.ReturnType {
|
||||
returnArgs = append(returnArgs, string(ra))
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ func NewBackgroundFailedEvent(err error, policy kyvernov1.PolicyInterface, rule
|
|||
}
|
||||
|
||||
func NewBackgroundSuccessEvent(source Source, policy kyvernov1.PolicyInterface, resources []kyvernov1.ResourceSpec) []Info {
|
||||
var events []Info
|
||||
events := make([]Info, 0, len(resources))
|
||||
msg := "resource generated"
|
||||
action := ResourceGenerated
|
||||
if source == MutateExistingController {
|
||||
|
|
|
@ -20,7 +20,7 @@ func StartInformers(ctx context.Context, informers ...informer) {
|
|||
}
|
||||
|
||||
func WaitForCacheSync(ctx context.Context, logger logr.Logger, informers ...informer) bool {
|
||||
var cacheSyncs []cache.InformerSynced
|
||||
cacheSyncs := make([]cache.InformerSynced, 0, len(informers))
|
||||
for i := range informers {
|
||||
cacheSyncs = append(cacheSyncs, informers[i].Informer().HasSynced)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func fetchUniqueKinds(rule kyvernov1.Rule) []string {
|
|||
}
|
||||
|
||||
func convertlist(ulists []unstructured.Unstructured) []*unstructured.Unstructured {
|
||||
var result []*unstructured.Unstructured
|
||||
result := make([]*unstructured.Unstructured, 0, len(ulists))
|
||||
for _, list := range ulists {
|
||||
result = append(result, list.DeepCopy())
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ func exemptExclusions(defaultCheckResults, excludeCheckResults []pssutils.PSSChe
|
|||
}
|
||||
}
|
||||
|
||||
var newDefaultCheckResults []pssutils.PSSCheckResult
|
||||
newDefaultCheckResults := make([]pssutils.PSSCheckResult, 0, len(defaultCheckResultsMap))
|
||||
for _, result := range defaultCheckResultsMap {
|
||||
newDefaultCheckResults = append(newDefaultCheckResults, result)
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ func parseField(field string) (string, []int, string, bool) {
|
|||
matchesIdx := regexIndex.FindAllStringSubmatch(field, -1)
|
||||
matchesStr := regexStr.FindAllString(field, -1)
|
||||
field = regexIndex.ReplaceAllString(field, "*")
|
||||
var indexes []int
|
||||
indexes := make([]int, 0, len(matchesIdx))
|
||||
for _, match := range matchesIdx {
|
||||
index, _ := strconv.Atoi(match[0])
|
||||
indexes = append(indexes, index)
|
||||
|
|
|
@ -131,7 +131,7 @@ func extract(
|
|||
}
|
||||
|
||||
func BuildStandardExtractors(tags ...string) []imageExtractor {
|
||||
var extractors []imageExtractor
|
||||
extractors := make([]imageExtractor, 0, 3)
|
||||
for _, tag := range []string{"initContainers", "containers", "ephemeralContainers"} {
|
||||
var t []string
|
||||
t = append(t, tags...)
|
||||
|
|
|
@ -12,7 +12,7 @@ func JoinPatches(patches ...[]byte) []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
var patchOperations []string
|
||||
patchOperations := make([]string, 0, len(patches))
|
||||
for _, patch := range patches {
|
||||
str := strings.TrimSpace(string(patch))
|
||||
if len(str) == 0 {
|
||||
|
|
|
@ -176,7 +176,7 @@ func EngineResponseToReportResults(response engineapi.EngineResponse) []policyre
|
|||
policyType := pol.GetType()
|
||||
annotations := pol.GetAnnotations()
|
||||
|
||||
var results []policyreportv1alpha2.PolicyReportResult
|
||||
results := make([]policyreportv1alpha2.PolicyReportResult, 0, len(response.PolicyResponse.Rules))
|
||||
for _, ruleResult := range response.PolicyResponse.Rules {
|
||||
result := ToPolicyReportResult(policyType, policyName, ruleResult, annotations, nil)
|
||||
results = append(results, result)
|
||||
|
|
|
@ -41,11 +41,11 @@ type CustomNamespaceLister struct {
|
|||
}
|
||||
|
||||
func (c *CustomNamespaceLister) List(selector labels.Selector) (ret []*corev1.Namespace, err error) {
|
||||
var namespaces []*corev1.Namespace
|
||||
namespace, err := c.dClient.GetKubeClient().CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
namespaces := make([]*corev1.Namespace, 0, len(namespace.Items))
|
||||
for _, ns := range namespace.Items {
|
||||
nsCopy := ns
|
||||
namespaces = append(namespaces, &nsCopy)
|
||||
|
|
|
@ -83,7 +83,7 @@ func ConvertValidatingAdmissionPolicyBinding(v1alpha1binding v1alpha1.Validating
|
|||
}
|
||||
|
||||
func convertRules(v1alpha1rules []v1alpha1.NamedRuleWithOperations) []v1beta1.NamedRuleWithOperations {
|
||||
var v1beta1rules []v1beta1.NamedRuleWithOperations
|
||||
v1beta1rules := make([]v1beta1.NamedRuleWithOperations, 0, len(v1alpha1rules))
|
||||
for _, r := range v1alpha1rules {
|
||||
v1beta1rules = append(v1beta1rules, v1beta1.NamedRuleWithOperations(r))
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func convertRules(v1alpha1rules []v1alpha1.NamedRuleWithOperations) []v1beta1.Na
|
|||
}
|
||||
|
||||
func convertValidations(v1alpha1validations []v1alpha1.Validation) []v1beta1.Validation {
|
||||
var v1beta1validations []v1beta1.Validation
|
||||
v1beta1validations := make([]v1beta1.Validation, 0, len(v1alpha1validations))
|
||||
for _, v := range v1alpha1validations {
|
||||
v1beta1validations = append(v1beta1validations, v1beta1.Validation(v))
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func convertValidations(v1alpha1validations []v1alpha1.Validation) []v1beta1.Val
|
|||
}
|
||||
|
||||
func convertAuditAnnotations(v1alpha1auditanns []v1alpha1.AuditAnnotation) []v1beta1.AuditAnnotation {
|
||||
var v1beta1auditanns []v1beta1.AuditAnnotation
|
||||
v1beta1auditanns := make([]v1beta1.AuditAnnotation, 0, len(v1alpha1auditanns))
|
||||
for _, a := range v1alpha1auditanns {
|
||||
v1beta1auditanns = append(v1beta1auditanns, v1beta1.AuditAnnotation(a))
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ func convertAuditAnnotations(v1alpha1auditanns []v1alpha1.AuditAnnotation) []v1b
|
|||
}
|
||||
|
||||
func convertMatchConditions(v1alpha1conditions []v1alpha1.MatchCondition) []v1beta1.MatchCondition {
|
||||
var v1beta1conditions []v1beta1.MatchCondition
|
||||
v1beta1conditions := make([]v1beta1.MatchCondition, 0, len(v1alpha1conditions))
|
||||
for _, m := range v1alpha1conditions {
|
||||
v1beta1conditions = append(v1beta1conditions, v1beta1.MatchCondition(m))
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ func convertMatchConditions(v1alpha1conditions []v1alpha1.MatchCondition) []v1be
|
|||
}
|
||||
|
||||
func convertVariables(v1alpha1variables []v1alpha1.Variable) []v1beta1.Variable {
|
||||
var v1beta1variables []v1beta1.Variable
|
||||
v1beta1variables := make([]v1beta1.Variable, 0, len(v1alpha1variables))
|
||||
for _, v := range v1alpha1variables {
|
||||
v1beta1variables = append(v1beta1variables, v1beta1.Variable(v))
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func convertVariables(v1alpha1variables []v1alpha1.Variable) []v1beta1.Variable
|
|||
}
|
||||
|
||||
func convertValidationActions(v1alpha1actions []v1alpha1.ValidationAction) []v1beta1.ValidationAction {
|
||||
var v1beta1actions []v1beta1.ValidationAction
|
||||
v1beta1actions := make([]v1beta1.ValidationAction, 0, len(v1alpha1actions))
|
||||
for _, a := range v1alpha1actions {
|
||||
v1beta1actions = append(v1beta1actions, v1beta1.ValidationAction(a))
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func convertValidationActions(v1alpha1actions []v1alpha1.ValidationAction) []v1b
|
|||
}
|
||||
|
||||
func ConvertMatchConditionsV1(v1alpha1conditions []v1alpha1.MatchCondition) []admissionregistrationv1.MatchCondition {
|
||||
var v1conditions []admissionregistrationv1.MatchCondition
|
||||
v1conditions := make([]admissionregistrationv1.MatchCondition, 0, len(v1alpha1conditions))
|
||||
for _, m := range v1alpha1conditions {
|
||||
v1conditions = append(v1conditions, admissionregistrationv1.MatchCondition(m))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue