File tree Expand file tree Collapse file tree 5 files changed +43
-2
lines changed
tests/KubeOps.Test/Operator/Entities Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 47
47
</AssemblyAttribute >
48
48
</ItemGroup >
49
49
50
+ <ItemGroup >
51
+ <Folder Include =" Testing" />
52
+ </ItemGroup >
53
+
50
54
</Project >
Original file line number Diff line number Diff line change 6
6
using System . Text ;
7
7
using System . Threading . Tasks ;
8
8
using k8s . Models ;
9
+ using KubeOps . Operator . Entities . Annotations ;
9
10
using KubeOps . Operator . Entities . Extensions ;
10
11
using KubeOps . Operator . Entities . Kustomize ;
11
12
using KubeOps . Operator . Serialization ;
@@ -75,15 +76,16 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
75
76
return ExitCodes . Success ;
76
77
}
77
78
78
- public static IEnumerable < V1CustomResourceDefinition > GenerateCrds ( )
79
+ public static IEnumerable < V1CustomResourceDefinition > GenerateCrds ( Assembly ? assembly = null )
79
80
{
80
- var assembly = Assembly . GetEntryAssembly ( ) ;
81
+ assembly ?? = Assembly . GetEntryAssembly ( ) ;
81
82
if ( assembly == null )
82
83
{
83
84
throw new Exception ( "No Entry Assembly found." ) ;
84
85
}
85
86
86
87
return GetTypesWithAttribute < KubernetesEntityAttribute > ( assembly )
88
+ . Where ( type => ! type . GetCustomAttributes < IgnoreEntityAttribute > ( ) . Any ( ) )
87
89
. Select ( EntityToCrdExtensions . CreateCrd ) ;
88
90
}
89
91
Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace KubeOps . Operator . Entities . Annotations
4
+ {
5
+ /// <summary>
6
+ /// Attribute that states that the given entity should be
7
+ /// ignored during CRD generation.
8
+ /// </summary>
9
+ [ AttributeUsage ( AttributeTargets . Class ) ]
10
+ public class IgnoreEntityAttribute : Attribute
11
+ {
12
+ }
13
+ }
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Reflection ;
3
4
using FluentAssertions ;
4
5
using k8s . Models ;
6
+ using KubeOps . Operator . Commands . Generators ;
5
7
using KubeOps . Operator . Entities . Extensions ;
6
8
using KubeOps . Test . Operator . Entities . TestEntities ;
7
9
using Xunit ;
@@ -217,5 +219,13 @@ public void Should_Set_Required_Null_If_No_Required()
217
219
var specProperties = crd . Spec . Versions . First ( ) . Schema . OpenAPIV3Schema . Properties [ "spec" ] ;
218
220
specProperties . Required . Should ( ) . BeNull ( ) ;
219
221
}
222
+
223
+ [ Fact ]
224
+ public void Should_Ignore_Entity_With_Ignore_Attribute ( )
225
+ {
226
+ var crds = CrdGenerator . GenerateCrds ( Assembly . GetExecutingAssembly ( ) ) . ToList ( ) ;
227
+ crds . Should ( ) . NotContain ( crd => crd . Spec . Names . Kind == "TestIgnoredEntity" ) ;
228
+ crds . Should ( ) . Contain ( crd => crd . Spec . Names . Kind == "TestSpecEntity" ) ;
229
+ }
220
230
}
221
231
}
Original file line number Diff line number Diff line change
1
+ using k8s . Models ;
2
+ using KubeOps . Operator . Entities ;
3
+ using KubeOps . Operator . Entities . Annotations ;
4
+
5
+ namespace KubeOps . Test . Operator . Entities . TestEntities
6
+ {
7
+ [ IgnoreEntity ]
8
+ [ KubernetesEntity ( Group = "kubeops.test.dev" , ApiVersion = "V1" ) ]
9
+ public class TestIgnoredEntity : CustomKubernetesEntity
10
+ {
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments