@@ -53,26 +53,30 @@ func (g *Gateway) getFlavours(w http.ResponseWriter, _ *http.Request) {
5353
5454 klog .Infof ("Found %d Flavours in the cluster" , len (flavours ))
5555
56+ availableFlavours := make ([]nodecorev1alpha1.Flavour , 0 )
57+
5658 // Filtering only the available flavours
5759 for i := range flavours {
5860 if ! flavours [i ].Spec .OptionalFields .Availability {
59- flavours = append (flavours [: i ] , flavours [i + 1 :] ... )
61+ availableFlavours = append (availableFlavours , flavours [i ] )
6062 }
6163 }
6264
63- klog .Infof ("Available Flavours: %d" , len (flavours ))
64- if len (flavours ) == 0 {
65+ klog .Infof ("Available Flavours: %d" , len (availableFlavours ))
66+ if len (availableFlavours ) == 0 {
6567 klog .Infof ("No available Flavours found" )
66- http .Error (w , "No Flavours found" , http .StatusNotFound )
68+ // Return content for empty list
69+ emptyList := make ([]* nodecorev1alpha1.Flavour , 0 )
70+ encodeResponseStatusCode (w , emptyList , http .StatusNoContent )
6771 return
6872 }
6973
7074 // Select the flavour with the max CPU
7175 max := resource .MustParse ("0" )
7276 index := 0
73- for i := range flavours {
74- if flavours [i ].Spec .Characteristics .Cpu .Cmp (max ) == 1 {
75- max = flavours [i ].Spec .Characteristics .Cpu
77+ for i := range availableFlavours {
78+ if availableFlavours [i ].Spec .Characteristics .Cpu .Cmp (max ) == 1 {
79+ max = availableFlavours [i ].Spec .Characteristics .Cpu
7680 index = i
7781 }
7882 }
@@ -118,17 +122,21 @@ func (g *Gateway) getFlavoursBySelector(w http.ResponseWriter, r *http.Request)
118122
119123 klog .Infof ("Found %d Flavours in the cluster" , len (flavours ))
120124
125+ availableFlavours := make ([]nodecorev1alpha1.Flavour , 0 )
126+
121127 // Filtering only the available flavours
122128 for i := range flavours {
123- if ! flavours [i ].Spec .OptionalFields .Availability {
124- flavours = append (flavours [: i ] , flavours [i + 1 :] ... )
129+ if flavours [i ].Spec .OptionalFields .Availability {
130+ availableFlavours = append (availableFlavours , flavours [i ] )
125131 }
126132 }
127133
128- klog .Infof ("Available Flavours: %d" , len (flavours ))
129- if len (flavours ) == 0 {
134+ klog .Infof ("Available Flavours: %d" , len (availableFlavours ))
135+ if len (availableFlavours ) == 0 {
130136 klog .Infof ("No available Flavours found" )
131- http .Error (w , "No Flavours found" , http .StatusNotFound )
137+ // Return content for empty list
138+ emptyList := make ([]* nodecorev1alpha1.Flavour , 0 )
139+ encodeResponseStatusCode (w , emptyList , http .StatusNoContent )
132140 return
133141 }
134142
@@ -140,7 +148,7 @@ func (g *Gateway) getFlavoursBySelector(w http.ResponseWriter, r *http.Request)
140148 }
141149
142150 klog .Infof ("Filtering Flavours by selector..." )
143- flavoursSelected , err := common .FilterFlavoursBySelector (flavours , selector )
151+ flavoursSelected , err := common .FilterFlavoursBySelector (availableFlavours , selector )
144152 if err != nil {
145153 http .Error (w , "Error getting the Flavours by selector" , http .StatusInternalServerError )
146154 return
@@ -150,7 +158,9 @@ func (g *Gateway) getFlavoursBySelector(w http.ResponseWriter, r *http.Request)
150158
151159 if len (flavoursSelected ) == 0 {
152160 klog .Infof ("No matching Flavours found" )
153- http .Error (w , "No Flavours found" , http .StatusNotFound )
161+ // Return content for empty list
162+ emptyList := make ([]* nodecorev1alpha1.Flavour , 0 )
163+ encodeResponse (w , emptyList )
154164 return
155165 }
156166
@@ -159,8 +169,8 @@ func (g *Gateway) getFlavoursBySelector(w http.ResponseWriter, r *http.Request)
159169 index := 0
160170
161171 for i := range flavoursSelected {
162- if flavours [i ].Spec .Characteristics .Cpu .Cmp (max ) == 1 {
163- max = flavours [i ].Spec .Characteristics .Cpu
172+ if flavoursSelected [i ].Spec .Characteristics .Cpu .Cmp (max ) == 1 {
173+ max = flavoursSelected [i ].Spec .Characteristics .Cpu
164174 index = i
165175 }
166176 }
0 commit comments