Skip to content

Commit 46c1269

Browse files
authored
Merge pull request #422 from derailed/rel_v0.21.7
Rel v0.21.7
2 parents 088ee40 + 1a2e75c commit 46c1269

File tree

20 files changed

+242
-176
lines changed

20 files changed

+242
-176
lines changed

.goreleaser.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ builds:
2020
goarch:
2121
- amd64
2222
- arm64
23-
- arm
23+
# - arm
2424
- ppc64le
2525
- s390x
26-
goarm:
27-
- 7
26+
# goarm:
27+
# - 7
2828
flags:
2929
- -trimpath
3030
ldflags:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NAME := popeye
22
PACKAGE := github.com/derailed/$(NAME)
3-
VERSION := v0.21.6
3+
VERSION := v0.21.7
44
GIT := $(shell git rev-parse --short HEAD)
55
DATE := $(shell date +%FT%T%Z)
66
IMG_NAME := derailed/popeye

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ Popeye is a readonly tool, it does not alter any of your Kubernetes resources in
1818

1919
[![Go Report Card](https://goreportcard.com/badge/github.com/derailed/popeye?)](https://goreportcard.com/report/github.com/derailed/popeye)
2020
[![codebeat badge](https://codebeat.co/badges/827e5642-3ccc-4ecc-b22b-5707dbc34cf1)](https://codebeat.co/projects/g.yxqyang.asia-derailed-popeye-master)
21-
[![Build Status](https://travis-ci.com/derailed/popeye.svg?branch=master)](https://travis-ci.com/derailed/popeye)
2221
[![release](https://img.shields.io/github/release-pre/derailed/popeye.svg)](https://github.com/derailed/popeye/releases)
23-
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/derailed/popeye/blob/master/LICENSE)
24-
[![docker](https://img.shields.io/docker/cloud/build/derailed/popeye?label=Docker&style=flat)](https://hub.docker.com/r/derailed/popeye/builds)
22+
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/derailed/popeye/blob/master/LICENSE)x
23+
[![Docker Repository on Quay](https://quay.io/repository/derailed/popeye/status "Docker Repository on Quay")](https://quay.io/repository/derailed/popeye)
2524
![GitHub stars](https://img.shields.io/github/stars/derailed/popeye.svg?label=github%20stars)
2625
[![Releases](https://img.shields.io/github/downloads/derailed/popeye/total.svg)]()
2726

@@ -274,12 +273,12 @@ popeye --s3-bucket=NAME-OF-YOUR-S3-BUCKET/OPTIONAL/SUBDIRECTORY --s3-region YOUR
274273
275274
## Docker Support
276275
277-
You can also run Popeye in a container by running it directly from the official docker repo on DockerHub.
276+
You can also run Popeye in a container by running it directly from the official docker repo on Quay.
278277
The default command when you run the docker container is `popeye`, so you customize the scan by using the supported cli flags.
279278
To access your clusters, map your local kubeconfig directory into the container with `-v` :
280279
281280
```shell
282-
docker run --rm -it -v $HOME/.kube:/root/.kube derailed/popeye --context foo -n bar
281+
docker run --rm -it -v $HOME/.kube:/root/.kube quay.io/derailed/popeye --context foo -n bar
283282
```
284283
285284
Running the above docker command with `--rm` means that the container gets deleted when Popeye exits.
@@ -293,7 +292,7 @@ docker run --rm -it \
293292
-v $HOME/.kube:/root/.kube \
294293
-e POPEYE_REPORT_DIR=/tmp/popeye \
295294
-v /tmp:/tmp \
296-
derailed/popeye --context foo -n bar --save --output-file my_report.txt
295+
quay.io/derailed/popeye --context foo -n bar --save --output-file my_report.txt
297296
298297
# Docker has exited, and the container has been deleted, but the file
299298
# is in your /tmp directory because you mapped it into the container

change_logs/release_v0.21.7.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<img src="https://raw.githubusercontent.com/derailed/popeye/master/assets/popeye_logo.png" align="right" width="200" height="auto"/>
2+
3+
# Release v0.21.7
4+
5+
## Notes
6+
7+
Thank you to all that contributed with flushing out issues and enhancements for Popeye! I'll try to mark some of these issues as fixed. But if you don't mind grab the latest rev and see if we're happier with some of the fixes! If you've filed an issue please help me verify and close. Your support, kindness and awesome suggestions to make Popeye better is as ever very much noticed and appreciated!
8+
9+
This project offers a GitHub Sponsor button (over here 👆). As you well know this is not pimped out by big corps with deep pockets. If you feel `Popeye` is saving you cycles diagnosing potential cluster issues please consider sponsoring this project!! It does go a long way in keeping our servers lights on and beers in our fridge.
10+
11+
Also if you dig this tool, please make some noise on social! [@kitesurfer](https://twitter.com/kitesurfer)
12+
13+
---
14+
15+
## Maintenance Release
16+
17+
---
18+
19+
## Resolved Issues
20+
21+
* [#414](https://github.com/derailed/popeye/issues/414) Why are there fewer inspection indicators in the new version (0.21.6)?
22+
* [#413](https://github.com/derailed/popeye/issues/413) new version 0.21.6 is not scaning any namespace
23+
* [#408](https://github.com/derailed/popeye/issues/408) v0.21.6 popeye -s po returns nothing and "Booms" with message "No linters matched query"
24+
* [#388](https://github.com/derailed/popeye/issues/388) Filter by namespace intermittently includes all namespaces
25+
26+
---
27+
28+
<img src="https://raw.githubusercontent.com/derailed/popeye/master/assets/imhotep_logo.png" width="32" height="auto"/>&nbsp; © 2024 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)

cmd/info.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Authors of Popeye
3+
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/derailed/popeye/internal/report"
10+
"github.com/derailed/popeye/pkg"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func init() {
15+
rootCmd.AddCommand(infoCmd())
16+
}
17+
18+
func infoCmd() *cobra.Command {
19+
return &cobra.Command{
20+
Use: "info",
21+
Short: "Prints Popeye info",
22+
Long: "Prints Popeye information",
23+
Run: func(cmd *cobra.Command, args []string) {
24+
printInfo()
25+
},
26+
}
27+
}
28+
29+
func printInfo() {
30+
printLogo(report.ColorAqua, report.ColorLighSlate)
31+
fmt.Println()
32+
printTuple("Logs", pkg.LogFile)
33+
}

cmd/root.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var (
3030
}
3131
)
3232

33+
func init() {
34+
initFlags()
35+
}
36+
3337
func execName() string {
3438
n := "popeye"
3539
if strings.HasPrefix(filepath.Base(os.Args[0]), "kubectl-") {
@@ -38,11 +42,6 @@ func execName() string {
3842
return n
3943
}
4044

41-
func init() {
42-
rootCmd.AddCommand(versionCmd())
43-
initFlags()
44-
}
45-
4645
// Execute root command
4746
func Execute() {
4847
if err := rootCmd.Execute(); err != nil {

cmd/version.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import (
88
"strings"
99

1010
"github.com/derailed/popeye/internal/report"
11-
"github.com/derailed/popeye/pkg"
1211
"github.com/spf13/cobra"
1312
)
1413

14+
func init() {
15+
rootCmd.AddCommand(versionCmd())
16+
}
17+
1518
func versionCmd() *cobra.Command {
1619
return &cobra.Command{
1720
Use: "version",
@@ -28,7 +31,6 @@ func printVersion() {
2831
printTuple("Version", version)
2932
printTuple("Commit", commit)
3033
printTuple("Date", date)
31-
printTuple("Logs", pkg.LogFile)
3234
}
3335

3436
func printTuple(section, value string) {

internal/alias.go

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ func (a *Aliases) Exclude(gvr types.GVR, sections []string) bool {
219219
if len(sections) == 0 {
220220
return false
221221
}
222+
222223
var matches int
223224
for _, s := range sections {
224225
agvr, ok := a.aliases[s]

internal/cilium/lint/ccnp.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ func (s *CiliumClusterwideNetworkPolicy) matchNodesBySel(sel api.EndpointSelecto
128128
if !ok {
129129
return nil, fmt.Errorf("expecting node but got %s", o)
130130
}
131-
fqn := client.FQN("", no.Name)
132-
if matchSelector(no.Labels, sel) {
133-
mm = append(mm, fqn)
131+
ll := make([]string, 0, len(no.Labels))
132+
for k, v := range no.Labels {
133+
ll = append(ll, k+"="+v)
134+
}
135+
if matchSelector(client.AllNamespaces, ll, sel) {
136+
mm = append(mm, client.FQN("", no.Name))
134137
}
135138
}
136139

@@ -148,9 +151,11 @@ func (s *CiliumClusterwideNetworkPolicy) matchCEPsBySel(sel api.EndpointSelector
148151
if !ok {
149152
return nil, fmt.Errorf("expecting cilium endpoint but got %s", o)
150153
}
151-
fqn := client.FQN(cep.Namespace, cep.Name)
152-
if matchSelector(cep.Labels, sel) {
153-
mm = append(mm, fqn)
154+
if cep.Status.Identity == nil {
155+
continue
156+
}
157+
if matchSelector(cep.Namespace, cep.Status.Identity.Labels, sel) {
158+
mm = append(mm, client.FQN(cep.Namespace, cep.Name))
154159
}
155160
}
156161

internal/cilium/lint/cid_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func TestCiliumIdentity(t *testing.T) {
3131
assert.Nil(t, li.Lint(test.MakeContext("cilium.io/v2/ciliumidentities", "ciliumidentities")))
3232
assert.Equal(t, 3, len(li.Outcome()))
3333

34-
li.Outcome().Dump()
3534
ii := li.Outcome()["default/100"]
3635
assert.Equal(t, 0, len(ii))
3736

internal/cilium/lint/cnp.go

+20-60
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ package lint
66
import (
77
"context"
88
"fmt"
9-
"strings"
109

10+
ciliumio "github.com/cilium/cilium/pkg/k8s/apis/cilium.io"
1111
v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
12-
slimv1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1"
12+
"github.com/cilium/cilium/pkg/labels"
1313
"github.com/cilium/cilium/pkg/policy/api"
1414
"github.com/derailed/popeye/internal"
1515
"github.com/derailed/popeye/internal/cilium"
@@ -111,76 +111,36 @@ func (s *CiliumNetworkPolicy) matchCEPsBySel(ns string, sel api.EndpointSelector
111111
if !ok {
112112
return nil, fmt.Errorf("expecting cilium endpoint but got %s", o)
113113
}
114-
fqn := client.FQN(cep.Namespace, cep.Name)
115-
if matchSelector(cep.Labels, sel) {
116-
mm = append(mm, fqn)
114+
if cep.Status.Identity == nil {
115+
continue
117116
}
118-
}
119-
120-
return mm, nil
121-
}
122117

123-
func matchSelector(labels map[string]string, sel api.EndpointSelector) bool {
124-
if len(labels) == 0 || sel.Size() == 0 {
125-
return false
126-
}
127-
if matchLabels(labels, sel.MatchLabels) {
128-
return true
129-
}
130-
131-
return matchExp(labels, sel.MatchExpressions)
132-
}
133-
134-
func matchExp(labels map[string]string, ee []slimv1.LabelSelectorRequirement) bool {
135-
for _, e := range ee {
136-
if matchSel(labels, e) {
137-
return true
118+
if matchSelector(cep.Namespace, cep.Status.Identity.Labels, sel) {
119+
mm = append(mm, client.FQN(cep.Namespace, cep.Name))
138120
}
139121
}
140122

141-
return false
123+
return mm, nil
142124
}
143125

144-
func matchSel(labels map[string]string, e slimv1.LabelSelectorRequirement) bool {
145-
key := strings.TrimPrefix(e.Key, "any.")
146-
_, ok := labels[key]
147-
if e.Operator == slimv1.LabelSelectorOpDoesNotExist && !ok {
126+
func matchSelector(ns string, ll []string, s api.EndpointSelector) bool {
127+
if s.Size() == 0 {
148128
return true
149129
}
150-
if !ok {
151-
return false
152-
}
153130

154-
switch e.Operator {
155-
case slimv1.LabelSelectorOpNotIn:
156-
for _, v := range e.Values {
157-
if v1, ok := labels[key]; ok && v1 == v {
158-
return false
159-
}
160-
}
161-
return true
162-
case slimv1.LabelSelectorOpIn:
163-
for _, v := range e.Values {
164-
if v == labels[key] {
165-
return true
166-
}
131+
sel := labels.NewLabelsFromModel(ll)
132+
if !client.IsAllNamespace(ns) {
133+
sel[ciliumio.PodNamespaceMetaNameLabel] = labels.Label{
134+
Key: ciliumio.PodNamespaceMetaNameLabel,
135+
Value: ns,
136+
Source: labels.LabelSourceK8s,
167137
}
168-
return false
169-
case slimv1.LabelSelectorOpExists:
170-
return true
171-
}
172-
173-
return false
174-
}
175-
176-
func matchLabels(labels, sel map[string]string) bool {
177-
var count int
178-
for k, v := range sel {
179-
k = strings.TrimPrefix(k, "any.")
180-
if v1, ok := labels[k]; ok && v == v1 {
181-
count++
138+
sel[ciliumio.PodNamespaceLabel] = labels.Label{
139+
Key: ciliumio.PodNamespaceLabel,
140+
Value: ns,
141+
Source: labels.LabelSourceK8s,
182142
}
183143
}
184144

185-
return count > 0
145+
return s.Matches(sel.LabelArray())
186146
}

internal/cilium/lint/cnp_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func TestCiliumNetworkPolicy(t *testing.T) {
2828
assert.Nil(t, li.Lint(test.MakeContext("cilium.io/v2/ciliumnetworkpolicies", "ciliumnetworkpolicies")))
2929
assert.Equal(t, 4, len(li.Outcome()))
3030

31-
li.Outcome().Dump()
3231
ii := li.Outcome()["default/cnp1"]
3332
assert.Equal(t, 0, len(ii))
3433

internal/cilium/lint/testdata/cep/1.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ items:
2626
- k8s:io.cilium.k8s.policy.cluster=fred
2727
- k8s:io.cilium.k8s.policy.serviceaccount=sa1
2828
- k8s:io.kubernetes.pod.namespace=default
29-
- k8s:app=p1
29+
- k8s:k8s-app=cep1
3030
named-ports:
3131
- name: dns
3232
port: 53
@@ -69,7 +69,7 @@ items:
6969
- k8s:io.cilium.k8s.policy.cluster=fred
7070
- k8s:io.cilium.k8s.policy.serviceaccount=sa1
7171
- k8s:io.kubernetes.pod.namespace=default
72-
- k8s:app=cid2
72+
- k8s:k8s-app=cep2
7373
named-ports:
7474
- name: dns
7575
port: 53

internal/client/client.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ func InitConnectionOrDie(config types.Config) (*APIClient, error) {
6464
config: config,
6565
cache: cache.NewLRUExpireCache(cacheSize),
6666
}
67-
_, err := a.serverGroups()
68-
if err != nil {
69-
return nil, err
67+
if _, err := a.serverGroups(); err != nil {
68+
return nil, fmt.Errorf("init connection fail: %w", err)
7069
}
7170
if err := a.supportsMetricsResources(); err != nil {
7271
log.Warn().Err(err).Msgf("no metrics server detected")
@@ -366,7 +365,7 @@ func (a *APIClient) serverGroups() (*metav1.APIGroupList, error) {
366365
dial, err := a.CachedDiscovery()
367366
if err != nil {
368367
log.Warn().Err(err).Msgf("Unable to dial discovery API")
369-
return nil, err
368+
return nil, fmt.Errorf("unable to dial discovery: %w", err)
370369
}
371370
apiGroups, err := dial.ServerGroups()
372371
if err != nil {
@@ -391,7 +390,7 @@ func (a *APIClient) supportsMetricsResources() error {
391390

392391
gg, err := a.serverGroups()
393392
if err != nil {
394-
return err
393+
return fmt.Errorf("supportmetricsResources call fail: %w", err)
395394
}
396395
for _, grp := range gg.Groups {
397396
if grp.Name != metricsapi.GroupName {

0 commit comments

Comments
 (0)