Skip to content

Commit dd185e9

Browse files
authored
Merge pull request #1699 from kube-logging/obsolete-deprecation
chore: remove obsolete deprecation warning from logging status
2 parents 3ccf034 + 8e15ccf commit dd185e9

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

controllers/logging/logging_controller_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ func TestLogginResourcesWithNonUniqueLoggingRefs(t *testing.T) {
279279
},
280280
Spec: v1beta1.LoggingSpec{
281281
ControlNamespace: controlNamespace,
282+
WatchNamespaces: []string{"a", "b"},
282283
},
283284
}
284285
logging2 := &v1beta1.Logging{
@@ -287,6 +288,7 @@ func TestLogginResourcesWithNonUniqueLoggingRefs(t *testing.T) {
287288
},
288289
Spec: v1beta1.LoggingSpec{
289290
ControlNamespace: controlNamespace,
291+
WatchNamespaces: []string{"b", "c"},
290292
},
291293
}
292294
logging3 := &v1beta1.Logging{
@@ -305,7 +307,7 @@ func TestLogginResourcesWithNonUniqueLoggingRefs(t *testing.T) {
305307

306308
// The first logging resource won't be populated with a warning initially since at the time of creation it is unique
307309
g.Eventually(getLoggingProblems(logging1)).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.BeEmpty())
308-
g.Eventually(getLoggingProblems(logging2)).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.ContainElement(gomega.ContainSubstring("Deprecated")))
310+
g.Eventually(getLoggingProblems(logging2)).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.ContainElement(gomega.ContainSubstring(model.LoggingRefConflict)))
309311
g.Eventually(getLoggingProblems(logging3)).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.BeEmpty())
310312

311313
g.Eventually(func() error {
@@ -316,7 +318,7 @@ func TestLogginResourcesWithNonUniqueLoggingRefs(t *testing.T) {
316318
l.Spec.ErrorOutputRef = "trigger reconcile"
317319
return mgr.GetClient().Update(context.TODO(), l)
318320
}).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.Succeed())
319-
g.Eventually(getLoggingProblems(logging1)).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.ContainElement(gomega.ContainSubstring("Deprecated")))
321+
g.Eventually(getLoggingProblems(logging1)).WithPolling(time.Second).WithTimeout(5 * time.Second).Should(gomega.ContainElement(gomega.ContainSubstring(model.LoggingRefConflict)))
320322
}
321323

322324
func getLoggingProblems(logging *v1beta1.Logging) func() ([]string, error) {

pkg/resources/model/reconciler.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"github.com/kube-logging/logging-operator/pkg/mirror"
3535
)
3636

37+
const LoggingRefConflict = "Other logging resources exist with the same loggingRef"
38+
3739
func NewValidationReconciler(
3840
repo client.StatusClient,
3941
resources LoggingResources,
@@ -291,13 +293,13 @@ func NewValidationReconciler(
291293
if l.Name == resources.Logging.Name {
292294
continue
293295
}
294-
if l.Spec.LoggingRef == resources.Logging.Spec.LoggingRef {
296+
if l.Spec.LoggingRef == resources.Logging.Spec.LoggingRef && hasIntersection(l.Status.WatchNamespaces, resources.Logging.Status.WatchNamespaces) {
295297
loggingsForTheSameRef = append(loggingsForTheSameRef, l.Name)
296298
}
297299
}
298300

299301
if len(loggingsForTheSameRef) > 0 {
300-
problem := fmt.Sprintf("Deprecated behaviour! Other logging resources exist with the same loggingRef: %s. This is going to be an error with the next major release.",
302+
problem := fmt.Sprintf("%s (%s) and their watchNamespaces conflict", LoggingRefConflict,
301303
strings.Join(loggingsForTheSameRef, ","))
302304
logger.Info(fmt.Sprintf("WARNING %s", problem))
303305
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, problem)
@@ -417,3 +419,14 @@ func jsonFieldName(f reflect.StructField) string {
417419
}
418420
return f.Name
419421
}
422+
423+
func hasIntersection(a, b []string) bool {
424+
for _, i := range a {
425+
for _, j := range b {
426+
if i == j {
427+
return true
428+
}
429+
}
430+
}
431+
return false
432+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright © 2024 Kube logging authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package model
16+
17+
import "testing"
18+
19+
func Test_hasIntersection(t *testing.T) {
20+
type args struct {
21+
a []string
22+
b []string
23+
}
24+
tests := []struct {
25+
name string
26+
args args
27+
want bool
28+
}{
29+
{
30+
name: "no intersection empty",
31+
args: args{
32+
a: []string{},
33+
b: []string{},
34+
},
35+
want: false,
36+
},
37+
{
38+
name: "no intersection nonempty",
39+
args: args{
40+
a: []string{"a", "b", "c"},
41+
b: []string{"d", "e"},
42+
},
43+
want: false,
44+
},
45+
{
46+
name: "has intersection",
47+
args: args{
48+
a: []string{"a", "b", "c"},
49+
b: []string{"b"},
50+
},
51+
want: true,
52+
},
53+
}
54+
for _, tt := range tests {
55+
t.Run(tt.name, func(t *testing.T) {
56+
if got := hasIntersection(tt.args.a, tt.args.b); got != tt.want {
57+
t.Errorf("hasIntersection() = %v, want %v", got, tt.want)
58+
}
59+
})
60+
}
61+
}

0 commit comments

Comments
 (0)